Added some simple error checking
Added some simple error checking