improve error handling and messages