Moved common functionality to helper class Sender and Receiver.