     else
       process.nextTick -> callback null, loginId
 
+
   @login$ = secure (client, credentials, callback) ->
-    {sessionToken: clientId, connection} = client
+
+    { sessionToken : clientId, connection } = client
     @login clientId, credentials, (err, response) ->
       return callback err  if err
       connection.delegate = response.account
       callback null, response
 
 
-  @login = (clientId, credentials, callback)->
+  @login = (clientId, credentials, callback) ->
 
     { username: loginId, password, groupIsBeingCreated
       groupName, tfcode, invitationToken } = credentials
 
+    user                  = null
+    session               = null
+    account               = null
+    username              = null
+    groupName            ?= 'koding'
+    invitation            = null
     bruteForceControlData = {}
-    session               = null
-    username              = null
-    user                  = null
-    account               = null
-    invitation            = null
-    groupName            ?= 'koding'
-
-    queue = [ =>
-      @normalizeLoginId loginId, (err, username_) ->
-        return callback err  if err
-
-        username = username_
-
-        queue.next()
-    , ->
-      # fetch session of the current requester
-      JSession.fetchSession clientId, (err, { session: fetchedSession })->
-        return callback err  if err
-
-        session = fetchedSession
-        unless session
-          console.error "login: session not found", username
-          return callback new KodingError "Couldn't restore your session!"
-
-        bruteForceControlData =
-          ip        : session.clientIP
-          username  : username
-
-        queue.next()
-
-    , ->
-      # todo add alert support(mail, log etc)
-      JLog.checkLoginBruteForce bruteForceControlData, (res) ->
-
-        unless res
-          return callback new KodingError \
-            "Your login access is blocked for #{JLog.timeLimit()} minutes."
-
-        queue.next()
-    , ->
-      # check credential validity
-      JUser.one { username }, (err, user_) ->
-
-        user = user_
-
-        return logAndReturnLoginError username, err.message, callback if err
-
-        # if user not found it means we dont know about given username
-        return logAndReturnLoginError username, 'Unknown user name', callback  unless user?
-
-        # if password is autogenerated return error
-        if user.getAt('passwordStatus') is 'needs reset'
-          return logAndReturnLoginError username, \
-            'You should reset your password in order to continue!', callback
-
-        # check if provided password is correct
-        unless user.checkPassword password
-          return logAndReturnLoginError username, 'Access denied!', callback
-
-        # check if user is using 2factor auth and provided key is ok
-        if !!(user.getAt 'twofactorkey')
-
-          if tfcode
+
+    queue = [
+
+      =>
+        @normalizeLoginId loginId, (err, username_) ->
+          return callback err  if err
+          username = username_
+          queue.next()
+
+      ->
+        # fetch session of the current requester
+        JSession.fetchSession clientId, (err, { session: fetchedSession }) ->
+          return callback err  if err
+
+          session = fetchedSession
+          unless session
+            console.error "login: session not found #{username}"
+            return callback new KodingError 'Couldn\'t restore your session!'
+
+          bruteForceControlData =
+            ip        : session.clientIP
+            username  : username
+
+          queue.next()
+
+      ->
+        # todo add alert support(mail, log etc)
+        JLog.checkLoginBruteForce bruteForceControlData, (res) ->
+          unless res
+            return callback new KodingError \
+              "Your login access is blocked for #{JLog.timeLimit()} minutes."
+
+          queue.next()
+
+      ->
+        # check credential validity
+        JUser.one { username }, (err, user_) ->
+          return logAndReturnLoginError username, err.message, callback if err
+          user = user_
+
+          # if user not found it means we dont know about given username
+          unless user?
+            return logAndReturnLoginError username, 'Unknown user name', callback
+
+          # if password is autogenerated return error
+          if user.getAt('passwordStatus') is 'needs reset'
+            return logAndReturnLoginError username, \
+              'You should reset your password in order to continue!', callback
+
+          # check if provided password is correct
+          unless user.checkPassword password
+            return logAndReturnLoginError username, 'Access denied!', callback
+
+          # check if user is using 2factor auth and provided key is ok
+          if !!(user.getAt 'twofactorkey')
+
+            unless tfcode
+              return callback new KodingError \
+                'TwoFactor auth Enabled', 'VERIFICATION_CODE_NEEDED'
+
             unless user.check2FactorAuth tfcode
               return logAndReturnLoginError username, 'Access denied!', callback
-          else
-            return callback new KodingError \
-              'TwoFactor auth Enabled', 'VERIFICATION_CODE_NEEDED'
-
-        # if everything is fine, just continue
-        queue.next()
-
-    , ->
-      # fetch account of the user, we will use it later
-      JAccount.one { "profile.nickname": username }, (err, account_)->
-        return callback new KodingError "couldn't find account!"  if err
-        account = account_
-        queue.next()
-
-    , =>
-      # check if user can access to group
-      #
-      # there can be two cases here
-      # # user is member, check validity
-      # # user is not member, and trying to access with invitationToken
-      # both should succeed
-
-      # if we dont have an invitation code, do not continue
-      return queue.next()  unless invitationToken
-
-      JInvitation = require '../invitation'
-      JInvitation.byCode invitationToken, (err, invitation_) =>
-        return callback err  if err
-        return callback new KodingError "invitation is not valid"  unless invitation_
-        invitation = invitation_
-        queue.next()
-
-    , =>
-      # check if user has pending invitation
-      return queue.next()  if invitationToken
-
-      JInvitation = require '../invitation'
-      options = { email: user.email, groupName }
-      JInvitation.one options, {}, (err, invitation_) =>
-        invitation = invitation_ if invitation_
-        queue.next()
-
-    , =>
-      return queue.next()  if groupIsBeingCreated
-      # check for membership
-      JGroup.one { slug: groupName }, (err, group) =>
-
-        return callback new KodingError err                   if err
-        return callback new KodingError 'group doesnt exist'  if not group
-
-        group.isMember account, (err , isMember)=>
-          return callback err  if err
-          return queue.next()  if isMember # if user is already member, we can continue
-
-          # addGroup will check all prerequistes about joining to a group
-          @addToGroup account, groupName, user.email, invitation, (err) ->
+
+          # if everything is fine, just continue
+          queue.next()
+
+      ->
+        # fetch account of the user, we will use it later
+        JAccount.one { 'profile.nickname' : username }, (err, account_) ->
+          return callback new KodingError 'couldn\'t find account!'  if err
+          account = account_
+          queue.next()
+
+      ->
+        # check if user can access to group
+        #
+        # there can be two cases here
+        # # user is member, check validity
+        # # user is not member, and trying to access with invitationToken
+        # both should succeed
+
+        # if we dont have an invitation code, do not continue
+        return queue.next()  unless invitationToken
+
+        JInvitation = require '../invitation'
+        JInvitation.byCode invitationToken, (err, invitation_) ->
+          return callback err  if err
+          return callback new KodingError 'invitation is not valid'  unless invitation_
+          invitation = invitation_
+          queue.next()
+
+      ->
+        # check if user has pending invitation
+        return queue.next()  if invitationToken
+
+        JInvitation = require '../invitation'
+        options = { email: user.email, groupName }
+        JInvitation.one options, {}, (err, invitation_) ->
+          invitation = invitation_ if invitation_
+          queue.next()
+
+      =>
+        return queue.next()  if groupIsBeingCreated
+        # check for membership
+        JGroup.one { slug: groupName }, (err, group) =>
+
+          return callback new KodingError err                   if err
+          return callback new KodingError 'group doesnt exist'  if not group
+
+          group.isMember account, (err , isMember) =>
             return callback err  if err
-            return queue.next()
-    , ->
-      return queue.next()  if groupIsBeingCreated
-      # we are sure that user can access to the group, set group name into
-      # cookie while logging in
-      session.update { $set : {groupName} }, (err) ->
-        return callback err  if err
-        queue.next()
-
-    , =>
-      # continue login
-      afterLogin user, clientId, session, (err, response) ->
-        callback err, response
-        queue.next()  unless err
+            return queue.next()  if isMember # if user is already member, we can continue
+
+            # addGroup will check all prerequistes about joining to a group
+            @addToGroup account, groupName, user.email, invitation, (err) ->
+              return callback err  if err
+              return queue.next()
+
+      ->
+        return queue.next()  if groupIsBeingCreated
+        # we are sure that user can access to the group, set group name into
+        # cookie while logging in
+        session.update { $set : { groupName } }, (err) ->
+          return callback err  if err
+          queue.next()
+
+      ->
+        # continue login
+        afterLogin user, clientId, session, (err, response) ->
+          callback err, response
+          queue.next()  unless err
+
     ]
 
     daisy queue
 
 
-  @verifyPassword = secure (client, options, callback)->
-    {connection: {delegate}} = client
-    {password, email} = options
+  @verifyPassword = secure (client, options, callback) ->
+
+    { password, email }           = options
+    { connection : { delegate } } = client
 
     # handles error and decide to invalidate pin or not
     # depending on email and user variables
-    handleError = (err, user) ->
+    handleError = (err, user, email) ->
       if email and user
         # when email and user is set, we need to invalidate verification token
         params =
-          action    : "update-email"
+          email     : email
+          action    : 'update-email'
           username  : user.username
-          email     : email
         JVerificationToken = require '../verificationtoken'
         JVerificationToken.invalidatePin params, (err) ->
           return console.error 'Pin invalidation error occurred', err  if err

    firstName = username  if not firstName or firstName is ''
    lastName  = ''        if not lastName

    if error = validateConvertInputAndReturnError userFormData, client
      return callback error

    if clientIP


      ->
        # fetching account, will be used to check login constraints of user
        user.fetchOwnAccount (err, account_) ->
          return callback err  if err
          account = account_
          queue.next()

      ->
        # checking login constraints
        checkLoginConstraints user, account, (err) ->
          return callback err  if err
          queue.next()

      ->
        # updating user passwordStatus if necessary
        updateUserPasswordStatus user, (err) ->
          return callback err  if err
          replacementToken = createId()
          queue.next()

