improve error handling