shutdown hook: update comments and refactor a bit, also add tests

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>