error handling and improved docs