Added some input checking