fix memory managment