Improve documentation and error handling