Caching: now works with main function.