Improved memory management