Registering a function for shutdown