Memory Management Error fixes