Memory management updates and code cleanup.