Improve error handling and feedback
Refactor and cleanup