fix shutdown sequence
add some code for later use
refactoring unit test, loacl 1:1 test, n:n test