Memory management and performance improvements