Moved out message processing code into own class.