Started to work on #1082: Implement proper termination detection during shutdown
More work on #1082
Merge branch 'fixing_1082'