fix to noninvertible matrices