Added check for invalid user input