fixing memoryleaks