bugfix a used variable before definition.
put the shutdown hook in the initialisation.