Add test of reordering, plus refactor to support it