optimise network.py