Refactor network code to separate client and server.