added comments and created functions to calculate and cache inverse matrix