optimized a loop