fixed typo in error messaging
more error handling, and fixed an error case