Added input error handling.