fixing memory allocation issue