Added some error checking for input