Properly handle exit signals