fixing logic for exceptions