works for some matrices. Trailing zeros are removed which messes up the algorithm