performance optimizations and memory reduction