adding exit handling