fix memory ownership