value ordering algorithm