fixed memory allocation issue