cache matrix code, working