   if not clientId and req.pendingCookies?.clientId
     clientId = req.pendingCookies.clientId
 
-  generateFakeClient (err, fakeClient) ->
-    return callback err  if err?
+  generateFakeClient {clientId, groupName, section}, (err, fakeClient, session) ->
+
+    return callback err  if err
+
     {delegate} = fakeClient.connection
 
-    # check if user stored in the session really exists
-    return callback null, fakeClient  if delegate?
+    updateCookie req, res, session
 
-    # when related guest user is somehow deleted and client stored in session is
-    # somehow invalid, create a new session
-    bongo.models.JSession.fetchSession {}, (err, {session, account})->
-      return callback err  if err?
+    return callback null, fakeClient
 
-      return callback {message: "account cannot be created"}  unless account? and session?
-      updateCookie req, res, session
 
-      prepareFakeClient fakeClient, {account, groupName, session}
+generateFakeClient = (options, callback) ->
 
-      callback null, fakeClient
-
-generateFakeClient = (callback) ->
+  {clientId, groupName, section} = options
 
   fakeClient    =
     context       :

generateFakeClientFromReq = (req, res, callback)->

  {clientId} = req.cookies
  {name: groupName, section} = req.params

  # TODO change this with Team product
  groupName = 'koding'

    impersonating : false


  return callback null, fakeClient  unless clientId

  bongo.models.JSession.fetchSession clientId, (err, response)->

    return handleError err, callback  if err

    {session} = response

    return handleError new Error "Session is not set", callback  unless session

    fetchGroupName { groupName, section }, (err, groupName)->
      return handleError err, callback  if err

      {username} = session

      prepareFakeClient fakeClient, {groupName, session, username}

      return callback null, fakeClient, session


prepareFakeClient = (fakeClient, options) ->
  {groupName, session, username} = options

  {JAccount} = bongo.models
  account = new JAccount
  account.profile.nickname = username
  account.type = 'unregistered'

  fakeClient.sessionToken = session.clientId

  # set username into context
