Significantly increase performance (using extended Euclid's algorithm)