Wrapped the duplex logic into it's own function.