Some memory usage improvements