get rid of double loop