Many small optimizations and tweaks