Refactored the client network code to generalize packet handling