optimizations and tweaks