first pass at cachematrix solution