Refactor network.js