Starting to add a simple stochastic optimisation function