Some optimizations of memory usage