Refactored the messaging part to angularjs