added checking for invalid input