Refactor network scan code - extract methods