fix memory management problem