fix a bug with mem calculation