Added a little error checking