fix error in loop