Implemented error handling