Fix p2p coding error and refine code