Cleaned up network selection code.