add label sorting function
remove some extra code