better labeling algo