Better memory deletion.
Fixed error in logical deletion.