Error handling and unit tests