Added some needed error handling