Fix code to work with bad input.