added some more error catching