create memorize function