Fix error message; move input validation to function.