Modified to visitor pattern.
Corrections (receivedMessages was cleared wrong).
Some documentation added.
Some comments added.