added cache matrix code