modify generate_ordering and added spec