Fixed an issue with memory management