Modularize and refactor some of the receiving code in preparation for longer message handling.