Some optimizations to reduce memory usage