Moved networking code into high cohesion functions