 			options.qs = query
 
 		# do request to request_token
-		request options, (e, r, body) ->
+		request options, (e, r, body) =>
 			return callback(e) if e
 			responseParser = new OAuth1ResponseParser(r, body, headers["Accept"], 'request_token')
 			return callback(responseParser.error) if responseParser.error
 
-			dbstates.setToken state.id, responseParser.oauth_token_secret, (e, r) ->
-				return callback e if e
-				authorize = provider.oauth1.authorize
-				query = {}
-				if typeof opts.options?.authorize == 'object'
-					query = opts.options.authorize
-				for name, value of authorize.query
-					param = replace_param value, @_params, state:state.id, callback:config.host_url+config.relbase, parameters
-					query[name] = param if param
-				query.oauth_token = responseParser.oauth_token
-				url = replace_param authorize.url, @_params, {}, parameters
-				url += "?" + querystring.stringify query
-				callback null, url
+			dbstates.setToken state.id, responseParser.oauth_token_secret, (e, r) =>
+				@_dbSetTokenCallback(e, r, state, provider, parameters, opts, responseParser, callback)
+
+	_dbSetTokenCallback: (e, r, state, provider, parameters, opts, responseParser, callback) ->
+		return callback e if e
+		authorize = provider.oauth1.authorize
+		query = {}
+		if typeof opts.options?.authorize == 'object'
+			query = opts.options.authorize
+		for name, value of authorize.query
+			param = @_replace_param value, @_params, state:state.id, callback:config.host_url+config.relbase, parameters
+			query[name] = param if param
+		query.oauth_token = responseParser.oauth_token
+		url = @_replace_param authorize.url, @_params, {}, parameters
+		url += "?" + querystring.stringify query
+		callback null, url
 
 	access_token: (state, req, callback) ->
 		if not req.params.oauth_token && not req.params.error


	_setParams: (parameters) ->
		@_params[k] = v for k,v of parameters

	authorize: (provider, parameters, opts, callback) ->
		@_setParams(provider.parameters)

			'accept-language':req.headers['accept-language']
			'content-type':req.headers['content-type']
		for name, value of oauthrequest.headers
			param = @_replace_param value, params, parameters.oauthio, parameters
			options.headers[name] = param if param

		# build body
