add function memoizing samples