Refactored network code to its own module.