Added some more error checking in the execute function