split networking code to its own file