Fixed memory allocation issue