Added some obvious error checking