fix some problems with memory