function extractToVariable(ast, start, end, text, scopes) {
        var doc                   = session.editor.document,
            editor = EditorManager.getActiveEditor(),
            parentExpn            = RefactoringUtils.getExpression(ast, start, end, doc.getText()),
            expns                 = [],
            parentBlockStatement,
            parentStatement;

        if (!parentExpn) {
            session.editor.displayErrorMessageAtCursor(Strings.ERROR_EXTRACTTO_VARIABLE_NOT_VALID);
            return;
        }

        // Find all expressions only if selected expn is not a subexpression
        // In case of subexpressions, ast cannot be used to find all expressions
        if (doc.getText().substr(parentExpn.start, parentExpn.end - parentExpn.start) === text) {
            parentBlockStatement = RefactoringUtils.findSurroundASTNode(ast, parentExpn, ["BlockStatement", "Program"]);
            expns                = findAllExpressions(parentBlockStatement, parentExpn, text);

            RefactoringUtils.getScopeData(session, editor.posFromIndex(expns[0].start)).done(function(scope) {
                var firstExpnsScopes = RefactoringUtils.getAllScopes(ast, scope, doc.getText()),
                    insertPostion;
                parentStatement = RefactoringUtils.findSurroundASTNode(ast, expns[0], ["Statement"]);
                if (scopes.length < firstExpnsScopes.length) {
                    var parentScope;
                    if (expns[0].body && expns[0].body.type === "BlockStatement") {
                        parentScope = firstExpnsScopes[firstExpnsScopes.length - scopes.length];
                    } else {
                        parentScope = firstExpnsScopes[firstExpnsScopes.length - scopes.length - 1];
                    }

                    var insertNode = RefactoringUtils.findSurroundASTNode(ast, parentScope.originNode, ["Statement"]);
                    if (insertNode) {
                        insertPostion = session.editor.posFromIndex(insertNode.start);
                    }
                }
                extract(scopes, parentStatement, expns, text, insertPostion);
            });
        } else {
            parentStatement = RefactoringUtils.findSurroundASTNode(ast, parentExpn, ["Statement"]);
            extract(scopes, parentStatement, [{ start: start, end: end }], text);
        }
    }
Creates params needed for extraction and calls extract
extract() does the actual extraction