Added some basic error checking