lots of small optimizations