Primitive functions. Divide might need to work better (gcd).