Factor out some functionality for peer management into Peer class.
only crash if this is not the first update.
Add unit test and fixes for peer.