Improving error catching