             materials: []
     else if icon.src.endsWith("web.gif")
         material = new Material
-            _id: activity.id,
+            _id: id,
             order: order,
             type: "link",
             indent: indent

    materials = []

    for activity, i in activities
        materials.push(parseActivity(activity, i, id==0))
    materials = await finalizeMaterialsList(materials)
    split = splitLevel(materials)
    materials = split.levels
    title = split.title

    return
        material: material
        tree: tree

makeLabelMaterial = (id, order, indent, content) ->
    material = new Material
        _id: id,
        order: order
        indent: indent
        type: "label",
        title: "",
        content: content,
        materials: []
    await material.upsert()
    return
        material: material
        tree: null

makeSpecialPage = (id, order, indent, element, keepResourcesInTree) ->
    a = element.getElementsByTagName("a")
    if a.length != 1
        logger.error("Found resource with != 1 children " + activity.innerHTML)
        return undefined
    return parseLink(a[0], id, order, keepResourcesInTree, indent, {src: ""})

parseLabel = (activity, order, keepResourcesInTree) ->
    indent = getIndent(activity)
    materials = []
    currentText = ""
    id = 0
    for child in activity.childNodes
        if child.classList?.contains("algoprog-page")
            if currentText
                materials.push(await makeLabelMaterial(activity.id + "_" + id, order + id, indent, currentText))
                currentText = ""
                id++
            materials.push(await makeSpecialPage(activity.id + "_" + id, order + id, indent, child, keepResourcesInTree))
            id++
        else
            currentText += child.outerHTML || child.nodeValue
    if currentText
        materials.push(await makeLabelMaterial(activity.id + "_" + id, order + id, indent, currentText))
    return materials

parseResource = (activity, order, keepResourcesInTree) ->
    indent = getIndent(activity)
    icon = activity.firstChild
    if activity.children.length != 2
        logger.error("Found resource with >2 children " + activity.innerHTML)
        return undefined
    a = activity.children[1]
    return parseLink(a, activity.id, order, keepResourcesInTree, indent, icon)

getProblem = (href, order) ->
    document = await downloadAndParse(href)
