Massive overhaul of networking code. Changes: