updated error catching