Fix bug in re-ordering