Refactor network communication