add type field to messages and rearange to match order