Fixing error codes, improving logging.