Refactored peer connection and added test.