Performance and memory usage improvements