added some needed error handling