Refactor messaging.cc