Improve completion function's wraparound logic. Fix completion function's origin-dependence.