More performance and memory optimizations