Fully commented and did small tweaks onto Matrix