Refactor label assignment and improve selection