optimised further! Got rid of another loop