minor loop optimizations