Reworked most of the p2p code