Implemented more error handling.