Added some validity checking.