factor out label handling