fixed singular matrix detection