added error handling for invalid user input.