various math and loop optimizations