           return callback err, []  if err or not vm
           JVM.fetchDomains {hostnameAlias: vm.hostnameAlias}, callback
 
-  @removeRelatedDomains = (vm)->
+  @removeRelatedDomains = (vm, callback=->)->
     vmInfo = @parseAlias vm.hostnameAlias
-    return  unless vmInfo
+    return callback null  unless vmInfo
 
     # Create same aliases based on vm info
     aliasesToDelete = @createAliases vmInfo


    JDomain = require './domain'
    JDomain.remove selector, (err)->
      return console.error "Failed to delete domains:", err  if err

  remove: (callback)->


      JVM.one {hostnameAlias}, (err, vm)=>
        return console.error err  if err or not vm
        # Old vm found

        # Removing old vm domains...
        JVM.removeRelatedDomains vm, (err)=>
          if err
            console.error "Failed to remove old domains for #{hostnameAlias}"

          JAccount.one {'profile.nickname':username}, (err, account)=>
            return console.error err  if err or not account
            # New account found

            vm.update {$set: {hostnameAlias: newHostNameAlias}}, (err)=>
              return console.error err  if err
              # VM hostnameAlias updated

              nameFactory = (require 'koding-counter')
                db          : JVM.getClient()
                offset      : 0
                counterName : "koding~#{username}~"
              nameFactory.next (err, uid)=>
                return console.error err  if err
                # Counter created

                JVM.ensureDomainSettings {
                  type:'user', nickname:username, groupSlug:'koding'
                  account, vm
                }

                console.log """Migration completed for
                               #{hostnameAlias} to #{newHostNameAlias}"""

    JGroup.on 'GroupDestroyed', (group)->
      group.fetchVms (err, vms)->
