Reorganize networking code