Fixed the StateWriter so that the optimisation_iteration counter is
incremented in the correct place