Close debug mode safely