fixes double memory deletion