Optimizations and tweaks