refactored network.c