Fixing exception handling