Added caching

Added caching results everywhere it is reasonable.