Fix a bug, which avoided clean shutdown