Some code cleanup, and moved network code to network.c