Cleanup and fixes for gcd and xgcd, plus better documentation and tests.