This should improve the memory usage of the current implementation. This change will need some heavy refactoring of the existing code.