Fix typo in error handling
More error handling and tests for such situations