added input error checking