Added some input checking.