optimizations, 2x speedup