fixed bad exception handling