Reworked selectPeer(). Thanks to yukaritan.