Added exit handling