* working on better Smith form algorithm