added logic for caching the solved matrix