Improved error checking in input