Fixed error catching