var _handleOrgUnitWithBorrowedSeries = function(ctx, courses, orgUnitWithBorrowedSeries, callback) {
    // If this organisational unit has no further borrowed series, we're done
    if (_.isEmpty(orgUnitWithBorrowedSeries.borrowedSeries)) {
        return callback();
    }

    var borrowedSeries = orgUnitWithBorrowedSeries.borrowedSeries.pop();

    // We need the *exported* organisational unit under which the series will be borrowed
    // as we need its id to do any database operations
    var parent = false;
    for (var i = 0; i < courses.length && !parent; i++) {
        parent = _findOrgUnit(courses[i].exportedCourse, orgUnitWithBorrowedSeries.metadata.exportedId);
    }

    // Find the *exported* series so we can borrow it under the organisational unit
    var series = false;
    for (i = 0; i < courses.length && !series; i++) {
        series = _findSeries(courses[i].exportedCourse, borrowedSeries.metadata.exportedId);
    }

    // If the parent or series couldn't be found, there is something wrong with the input data
    if (!parent || !series) {
        log().warn({
            'orgUnit': _.omit(orgUnitWithBorrowedSeries, 'series', 'borrowedSeries'),
            'series': _.omit(borrowedSeries, 'events')
        }, 'Could not borrow a series under a module');
        return callback();
    }

    // Get module and series instances
    OrgUnitDAO.getOrgUnit(parent.id, false, function(err, orgUnit) {
        if (err) {
            log().error({'err': err}, 'Could not get the parent module when borrowing a series');
            process.exit(1);
        }

        SeriesDAO.getSerie(series.id, false, function(err, series) {
            if (err) {
                log().error({'err': err}, 'Could not get the series when borrowing a series');
                process.exit(1);
            }

            // Borrow the series under the organisational unit
            OrgUnitDAO.addOrgUnitSeries(orgUnit, series, function(err) {
                if (err) {
                    log().error({
                        'err': err,
                        'parent': parent.id,
                        'series': series.id
                    }, 'Could not borrow the series under the organisational unit');
                    process.exit(1);
                }

                // Move on to the next borrowed series in this organisational unit
                return _handleOrgUnitWithBorrowedSeries(ctx, courses, orgUnitWithBorrowedSeries, callback);
            });
        });
    });
};
            OrgUnitTestsUtil.assertExportOrgUnit(global.tests.admins.cam2013.client, course.id, null, function(data) {

                // Create a cycle
                OrgUnitDAO.getOrgUnit(course.id, false, function(err, courseOrgUnit) {
                    assert.ok(!err);
                    OrgUnitDAO.updateOrgUnit(courseOrgUnit, {'ParentId': module.id}, function(err) {
                        assert.ok(!err);

                        // Verify we can no longer export the tree
                        OrgUnitTestsUtil.assertExportOrgUnitFails(global.tests.admins.cam2013.client, course.id, null, 400, function() {
                            return callback();
                        });
                    });
                });
            });