Modified to inverse matrix calculation