cleaner approach to creating and mutating matrices, while maintaining caching