attempt at optimisation - not quite working