for in loop optimization