Fixed issues with memory