More tests and cleaned up error handling for POSIX error codes