Fix error catching