inner loop optimizations