Draft 2 of cache matrix

updated to working code plus thorough commenting
fix typos

fix small typos in comments