enhanced error catching