--refactor code: extract subnetwork function to library