refactor network detect