fixed typo in error handling code; added tests for bad input