Trying to optimize memory usage