Unification algorithm