junction variable sorting, to make output deterministic