refactor network; add network test