fix memorize function