fix memory issues