fixed resources leaks when in the middle of a shutdown. Fixed peermap to
not see thirdhand information as firsthand information
fixed resource leak