Fixed error catching bug