Added check for valid user input.