Fix exit handling