More refactoring and porting of peer connection funcionality