added some error checking on input