fix a dead connection bug, and some small bugs