Memory management refactoring
Merge changes