Improve handling of bad input