fixed some error catching