Added some more intelligent error checking