move some functions to net.c from main.c