properly do graceful shutdown when receiving kill signal

this is slowly becoming a mess with all the different threads everywhere. this should go into a close method on a node, instead of calling system exit in the middle of the code

fixes #645