edited script for inverse matrix