fix memory filling bug