fixed problems with memory