Improve memory management