Overhaul queue compilation algo

Old algo wouldn't obey round robin order correctly. New implementation
is much more robust.