Added a pre-exit hook