We should have been using elementary divisors here all the time...