moved flatten into the messaging module