implemented QR factorization