Improved memory freeing