Various optimizations and enhancements