Refactoring registering shutdown_function