optimizations to reduce memory usage