Fixed a bug with Euclidean algorithm