Improve error handling

Done