fixing broken tests and adding error handling and messaging to source code