Functions for matrix cache homework