added some error catching