Refactor network code.