Added caching and set.seed