Added cache matrix functionality