converted 2 functions to support inverse matrix and added comments