Implemented more consistent error handling.