Added some more input checking