Decouple messages from IO; other minor changes