Extract order logic to make easier to test

[#65314350]

Signed-off-by: Abhijit Hiremagalur <abhi@pivotallabs.com>