This is really slow and a waste of time. In longer term, it would be good to work out how many optimization steps are needed / useful.