Updated error catching