improved error handling
fixed typo