restructured much of the main code into a new network handling library.