generate labels only when necessary