implemented error handling