Replaced while of main optimisation with for and hard coded maximum
number of iterations.
Removed debugging cout.