added check for positive definiteness to invert