added some input error checking