I ended up changing the code so it doesn't depend on a given order, but instead self-orders the elements. It feels more future-proof.