better checking for invalid input