Fixed setter function in loop