fixed bug in assigning labels