More corrections concerning memory allocation/deallocation. Bug seems to be fixed now. Tests successful.