Added code to solve and cache previously solved matrices