fixed infinite loop with bad input