Reorganized code to prepare for server message parsing