           queue.next()
 
       =>
-        if aNewRegister
-
-          userInfo = { username, firstName, lastName,
-            email, password, emailFrequency }
-
-          @createUser userInfo, (err, _user, _account)=>
-            return callback err  if err
-
-            if _user? and _account?
-
-              [account, user] = [_account, _user]
-              queue.next()
-
-            else
-
-              return callback new KodingError "Failed to create user!"
+        userInfo =
+          email          : email
+          username       : username
+          password       : password
+          lastName       : lastName
+          firstName      : firstName
+          emailFrequency : emailFrequency
+
+        @createUser userInfo, (err, user_, account_) ->
+          return callback err  if err
+
+          if user_? and account_?
+            [account, user] = [account_, user_]
+            queue.next()
+
+          else
+            return callback new KodingError 'Failed to create user!'
+
+      ->
+        if ip? and country? and region?
+          locationModifier =
+            $set                       :
+              'registeredFrom.ip'      : ip
+              'registeredFrom.region'  : region
+              'registeredFrom.country' : country
+
+          user.update locationModifier, ->
+            queue.next()
 
         else
           queue.next()
 
       =>
-        if not aNewRegister and username? and email?
-          options = { account, oldUsername, email, username }
-          @changeEmailByUsername options, (err) =>
-            return callback err  if err
-            queue.next()
-        else
-          queue.next()
-
-      ->
-        if not aNewRegister
-          account.fetchUser (err, user_) ->
-            return callback err  if err
-            user = user_
-            queue.next()
-        else
-          queue.next()
-
-      ->
-        if ip? and country? and region?
-          locationModifier = $set    :
-            "registeredFrom.ip"      : ip
-            "registeredFrom.country" : country
-            "registeredFrom.region"  : region
-          user.update locationModifier, -> queue.next()
-        else
-          queue.next()
-
-      =>
-        oauthUser = if aNewRegister then username else oldUsername
-
-        @persistOauthInfo oauthUser, client.sessionToken, (err)=>
+        oauthUser =  username
+        @persistOauthInfo oauthUser, client.sessionToken, (err) ->
           return callback err  if err
           queue.next()
 
       =>
-        if aNewRegister and username?
-          options = {
+        if username?
+          options =
             account        : account
             username       : username
             clientId       : clientId
+            groupName      : client.context.group
             isRegistration : yes
-            groupName      : client.context.group
-          }
-
-          @changeUsernameByAccount options, (err, newToken_) =>
+
+          @changeUsernameByAccount options, (err, newToken_) ->
             return callback err  if err
             newToken = newToken_
             queue.next()
+
         else
           queue.next()
 
       ->
-        account.update $set: type: 'registered', (err) ->
+        account.update { $set: { type: 'registered' } }, (err) ->
           return callback err  if err?
           queue.next()
 


      ->
        # don't block register
        callback error, {account, newToken}
        queue.next()

      ->
        {secret, confirmExpiresInMinutes} = KONFIG.jwt
        {publicHostname} = KONFIG

        jwt   = require 'jsonwebtoken'

        # uses 'HS256' as default for signing
        token = jwt.sign { username }, secret, { expiresInMinutes: confirmExpiresInMinutes }

        Tracker.identify username, { jwtToken: token, email, pin }
        queue.next()

      ->
        {username, email} = user
        subject           = Tracker.types.START_REGISTER
        Tracker.track username, { to : email, subject }
        queue.next()

      ->
        SiftScience = require "../siftscience"
        SiftScience.createAccount client, referrer, ->

    ]


  @convert = secure (client, userFormData, callback) ->

    { slug
      email
      agree
      username
      lastName
      referrer
      password
      firstName
      recaptcha
      emailFrequency
      invitationToken
      passwordConfirm }         = userFormData

    { clientIP
      connection }              = client

    { delegate : account }      = connection
    { nickname : oldUsername }  = account.profile
    { sessionToken : clientId } = client

    # if firstname is not received use username as firstname
    firstName = username  if not firstName or firstName is ''
    lastName  = ''        if not lastName

    # only unregistered accounts can be "converted"
    if account.type is 'registered'
      return callback new KodingError 'This account is already registered.'

    if /^guest-/.test username
      return callback new KodingError 'Reserved username!'

    if username is 'guestuser'
      return callback new KodingError 'Reserved username: \'guestuser\'!'

    if password isnt passwordConfirm
      return callback new KodingError 'Passwords must match!'

    if clientIP
      { ip, country, region } = Regions.findLocation clientIP

    pin              = null
    user             = null
    error            = null
    newToken         = null
    invitation       = null
    quotaExceedErr   = null
    foreignAuthType  = null

    queue = [

      =>
        @extractOauthFromSession client.sessionToken, (err, foreignAuthInfo) ->
          console.log 'Error while getting oauth data from session', err  if err

          foreignAuthType = foreignAuthInfo?.foreignAuthType

