re-written key ordering code to avoid node range discrepancy