Rewrite lazy and memoize functions.