made euclidean algorithm use mod