Fixed some races and memory leaks on connection / disconnection