fix unit test
add shutdown hook, and shutdown fixes