fix memory corruption bug