fix memory allocation