better error handling and documentation