issue #667 attempt

fixing memory leak cleaning