Get rid of the double loop