added optimisation code