fix a bug w.r.t. term ordering