Tidied up the optimisation stuff