fixing shutdown handling, fixing valgrind uninitialized data warning