Two main functions for network construction.