fix a bug that eat up the whole memory