Improved exception handled logic