try some simple loop optimizations