updated to invert matrices, per assignment

reworked template routines
changed variable names to remove scope confusion
Still needs work on comments.