shutdown hook extracted as function