optimization in loop format