added factory for caching mains state