more reordering logic, bugfix for xml config