added some input validation