solving the huge memory allocation issue