             else if not username? or not email?
               return callback createKodingError 'Username and email are required fields'
 
-            @verifyKodingenPassword {username, password, kodingenUser}, (err)=>
+            @verifyKodingenPassword {username, password, kodingenUser}, (err) =>
               if err
                 return callback createKodingError 'Wrong password'
               else
-                nickname = username
-                JSession.one {clientId: client.sessionToken}, (err, session)=>
+                JSession.one {clientId: client.sessionToken}, (err, session) =>
                   if err
                     callback err
                   else unless session
                     callback createKodingError 'Could not restore your session!'
                   else
-                    slug = {
-                      slug: username,
-                      constructorName: 'JUser',
-                      usedAsPath: 'username',
-                      collectionName: 'jUsers'
+                    userData = {
+                      username, password, email, firstName, lastName
                     }
-                    JName.claim username, [slug], 'JUser', (err)=>
-                      if err then callback err
-                      else
-                        salt = createSalt()
-                        user = new JUser {
-                          username
-                          email
-                          salt
-                          password: hashPassword(password, salt)
-                          emailFrequency: {
-                            global         : on
-                            daily          : on
-                            privateMessage : on
-                            followActions  : off
-                            comment        : on
-                            likeActivities : off
-                            groupInvite    : on
-                            groupRequest   : on
-                            groupApproved  : on 
-                          }
-                        }
-                        user.save (err)=>
-                          if err
-                            if err.code is 11000
-                              callback createKodingError "Sorry, \"#{email}\" is already in use!"
-                            else callback err
-                          else
-                            hash = getHash email
-                            account = new JAccount
-                              profile: {
-                                nickname
-                                firstName
-                                lastName
-                                hash
-                              }
-                            account.save (err)=>
-                              if err then callback err
-                              else user.addOwnAccount account, (err)=>
-                                if err then callback err
-                                else @addToGroups account, invite, entryPoint, (err)->
-                                  if err then callback err
-                                  else if silence
-                                    JUser.grantInitialInvitations user.username
-                                    createNewMemberActivity account
-                                    callback null, account
-                                  else
-                                    replacementToken = createId()
-                                    session.update {
-                                      $set:
-                                        username      : user.username
-                                        lastLoginDate : new Date
-                                        clientId      : replacementToken
-                                      $unset          :
-                                        guestId       : 1
-                                    }, (err, docs)->
-                                      if err then callback err
-                                      else
-                                        user.sendEmailConfirmation()
-                                        JUser.grantInitialInvitations user.username
-                                        JUser.emit 'UserCreated', user
-                                        createNewMemberActivity account
-                                        JAccount.emit "AccountAuthenticated", account
-                                        callback null, account, replacementToken
+                    @createUser userData, (err, user, account) =>
+                      return callback err  if err
+                      @addToGroups account, invite, entryPoint, (err) ->
+                        if err then callback err
+                        else if silence
+                          JUser.grantInitialInvitations user.username
+                          createNewMemberActivity account
+                          callback null, account
+                        else
+                          replacementToken = createId()
+                          session.update {
+                            $set:
+                              username      : user.username
+                              lastLoginDate : new Date
+                              clientId      : replacementToken
+                            $unset          :
+                              guestId       : 1
+                          }, (err, docs) ->
+                            if err then callback err
+                            else
+                              user.sendEmailConfirmation()
+                              JUser.grantInitialInvitations user.username
+                              JUser.emit 'UserCreated', user
+                              createNewMemberActivity account
+                              JAccount.emit "AccountAuthenticated", account
+                              callback null, account, replacementToken
+
 
   @grantInitialInvitations = (username)->
     JInvitation.grant {'profile.nickname': username}, 3, (err)->

        @addToGroup account, invite.group or entryPoint, invite.group?, callback
      else callback null

  @register = secure (client, userFormData, callback)->
    {connection} = client
    {username, email, password, passwordConfirm, firstName, lastName,

    # means no welcome e-mail for new users.
    # We're using it for migrating Kodingen users to Koding
    silence  = no
    if client.connection?.delegate?.can? 'migrate-kodingen-users'
      {silence} = userFormData

    @usernameAvailable username, (err, r)=>
