Cleanup in main_loop()