added input validation and nicer error reporting