Added caching for performance improvements.