did some refactoring in the search of a working shutdown hook