now accepts only square matrix