initial refactoring of networking logic