fix memory usage problems