core: improve label handling