fixes to optimiser