updated error handling as well as fixed a typo