Added more error catching