refactoring messaging module