Refactored the code, using mediator pattern.