added better input error checking