Fix wrong variable names in loop