fixed a minor memory leak happening in certain cases during the node shutdown phase

also minor cleanings and some debugging messages