Correct variables in second loop