Add error handling and fix unit test creating nulls