Fixed the memory errors