Added some minor error checking