cleaned networking code