refactor network manager code