Fix various type-conversion issues, in particular finding the GCD of types.