Implemented error handling and other functions