major cleanup of networking code