modified Inverse Matrix Code