added some more error handling