Added some input validation.