Fix issue with memory allocation