         else user.update { $set: { uid } }, handleError
 
     JAccount.on 'UsernameChanged', (oldUsername, newUsername) ->
-      # JVM.each name: ///^\w+~#{oldUsername}~///, (err, vm) ->
-      #   groupName = vm.name.substr 0, vm.name.indexOf '~'
-      #   hostnameAlias = vm.hostnameAlias.map (alias)->
-      #     edges = alias.split '.'
-      #     console.log edges
+      re = ///^\w+~#{oldUsername}~///
+      JVM.each name: re, {}, (err, vm) ->
+        return callback err  if err?
+
+        if vm?
+          [groupSlug] = vm.name.split '~'
+
+          name = "#{groupSlug}~#{newUsername}~#{vm.uid}"
+
+          JVM.removeDomains vm.hostnameAlias  if vm.hostnameAlias?
+
+          hostnameAlias = JVM.createAliases {
+            nickname  : newUsername
+            type      : vm.type
+            uid       : vm.uid
+            groupSlug
+          }
+
+          JVM.createDomains hostnameAlias
+
+          vm.update $set: { name, hostnameAlias }, (err) ->
+            console.error err  if err?
 
     JGroup.on 'GroupCreated', ({group, creator})->
       group.fetchBundle (err, bundle)->
-        console.log err, bundle
         if err then handleError err
         else if bundle and bundle.sharedVM
           creator.fetchUser (err, user)->

        regYears      : 0
      ).save (err)-> console.log err  if err?

  @createAliases = ({nickname, type, uid, groupSlug})->
    domain       = 'kd.io'
    aliases      = []

                          ]
      instance          : []
    schema              :
      type              :
        type            : String
        enum            : ['invalid vm type', ['user', 'group']]
      uid               : Number
      ip                :
        type            : String
        default         : -> null
