separate loops for optimisation