fix memory corruption