   breadcrumb = makeBreadcrumb parent
 
   # get root category
-  query('SELECT cid, name, description FROM cpg11d_categories WHERE parent = ? ORDER BY pos', [categoryId]).spread (categories) ->
+  query('SELECT cid, name, description FROM cpg11d_categories WHERE parent = ? ORDER BY pos DESC', [categoryId]).spread (categories) ->
     Q.all categories.map (coppermineCategory) ->
       return null if coppermineCategory.cid in CATEGORY_BLACKLIST
 

        subalbums: []
        pictures: []

      processAlbum edegalAlbum, albumId: coppermineCategory.cid

convertAlbums = (categoryId, parent) ->
  breadcrumb = makeBreadcrumb parent

  query('SELECT aid, title, description FROM cpg11d_albums WHERE category = ? ORDER BY pos', [categoryId]).spread (albums) ->
    Q.all albums.map (coppermineAlbum) ->
      decodeEntities coppermineAlbum, 'title', 'description'
      slug = slugify(coppermineAlbum.title) or "album-#{coppermineAlbum.aid}"

        subalbums: []
        pictures: []

      processAlbum edegalAlbum, parent: parent, albumId: coppermineAlbum.aid, parent: parent

processAlbum = (edegalAlbum, opts) ->
  {albumId, categoryId, parent} = opts

  getAlbum(edegalAlbum.path).then (existingAlbum) ->
    edegalAlbum = existingAlbum if existingAlbum?

    work = []
    work.push convertSubcategories(categoryId, edegalAlbum) if categoryId
    work.push convertAlbums(categoryId, edegalAlbum) if categoryId
    work.push convertPictures(albumId, edegalAlbum) if albumId and not existingAlbum?
    Q.all(work).then ->
      setThumbnail edegalAlbum

      unless _.find(parent.subalbums, (subalbum) -> subalbum.path == edegalAlbum.path)
        parent.subalbums.unshift _.pick edegalAlbum, 'path', 'title', 'thumbnail'

      saveAlbum edegalAlbum

      if existingAlbum
        process.stdout.write '-'
      else
        process.stdout.write '.'

convertPictures = (albumId, parent) ->
  query('SELECT pid, filename, filepath, title, caption FROM cpg11d_pictures WHERE aid = ? ORDER BY filename', [albumId]).spread (pictures) ->
