modified code for inverse matrix