improve error handling
fixed #3