fix memory problems