Do some refinements and add code for the messaging functions.