refine for loop