diff --git a/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java b/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java
index f9f5d004d7d189a074d246d4fbaf0416e2a4582f..461c6592002d0c55f42a29fc77601c51bca15cec 100644
--- a/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java
+++ b/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java
@@ -1024,29 +1024,31 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
         Map<Long, IOFSwitch>  switches = floodlightProvider.getSwitches();
         Map<IOFSwitch, ClusterDFS> dfsList = new HashMap<IOFSwitch, ClusterDFS>();
 
-        for (Long key: switches.keySet()) {
-            IOFSwitch sw = switches.get(key);
-            ClusterDFS cdfs = new ClusterDFS(); 
-            dfsList.put(sw, cdfs);
-        }
+        if (switches.keySet() != null) {
+            for (Long key: switches.keySet()) {
+                IOFSwitch sw = switches.get(key);
+                ClusterDFS cdfs = new ClusterDFS();
+                dfsList.put(sw, cdfs);
+            }
 
-        // Get a set of switch keys in a set
-        Set<IOFSwitch> currSet = new HashSet<IOFSwitch>();
+            // Get a set of switch keys in a set
+            Set<IOFSwitch> currSet = new HashSet<IOFSwitch>();
 
-        for (Long key: switches.keySet()) {
-            IOFSwitch sw = switches.get(key);
-            ClusterDFS cdfs = dfsList.get(sw);
-            if (cdfs == null) {
-                log.error("Do DFS object for key found.");
-            }else if (!cdfs.isVisited()) {
-                this.dfsTraverse(1, sw, switches, dfsList, currSet, clusters);
+            for (Long key: switches.keySet()) {
+                IOFSwitch sw = switches.get(key);
+                ClusterDFS cdfs = dfsList.get(sw);
+                if (cdfs == null) {
+                    log.error("Do DFS object for key found.");
+                }else if (!cdfs.isVisited()) {
+                    this.dfsTraverse(0, 1, sw, switches, dfsList, currSet, clusters);
+                }
             }
         }
 
         updates.add(new Update(UpdateOperation.CLUSTER_MERGED));
     }
 
-    protected long dfsTraverse (long currIndex, 
+    protected long dfsTraverse (long parentIndex, long currIndex, 
             IOFSwitch currSw, Map<Long, IOFSwitch> switches, 
             Map<IOFSwitch, ClusterDFS> dfsList, Set <IOFSwitch> currSet, 
             Set <SwitchCluster> clusters) {
@@ -1059,7 +1061,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
         //Assign the DFS object with right values.
         currDFS.setVisited(true);
         currDFS.setDfsIndex(currIndex);
-        currDFS.setLowpoint(currIndex);
+        currDFS.setParentDfsIndex(parentIndex);
         currIndex++;
 
         // Traverse the graph through every outgoing link.
@@ -1083,7 +1085,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
 
                 } else if (!dstDFS.isVisited()) {
                     // make a DFS visit
-                    currIndex = dfsTraverse(currIndex, dstSw,
+                    currIndex = dfsTraverse(currDFS.getDfsIndex(), currIndex, dstSw,
                             switches, dfsList, currSet, clusters);
 
                     // update lowpoint after the visit
@@ -1102,20 +1104,17 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener,
         // If the node's lowpoint is greater than its parent's DFS index,
         // we need to form a new cluster with all the switches in the 
         // currSet.
-        if (currDFS.getLowpoint() == currDFS.getDfsIndex()) {
+        if (currDFS.getLowpoint() > currDFS.getParentDfsIndex()) {
             // The cluster thus far forms a strongly connected component.
             // create a new switch cluster and the switches in the current
             // set to the switch cluster.
             SwitchCluster sc = new SwitchCluster();
-            Iterator<IOFSwitch> e = currSet.iterator(); 
-            while (e.hasNext()) {
-                IOFSwitch sw = e.next();
+            for(IOFSwitch sw: currSet){
                 sc.add(sw);
                 switchClusterMap.put(sw, sc);
             }
             // delete all the nodes in the current set.
             currSet.clear();
-
             // add the newly formed switch clusters to the cluster set.
             clusters.add(sc);
         }
diff --git a/src/main/java/net/floodlightcontroller/util/ClusterDFS.java b/src/main/java/net/floodlightcontroller/util/ClusterDFS.java
index 74d0fb0a3f500c6e34ef646d1f6c13f229be0651..63e151d06391cda0b7293ed14fad0b8895a24a22 100644
--- a/src/main/java/net/floodlightcontroller/util/ClusterDFS.java
+++ b/src/main/java/net/floodlightcontroller/util/ClusterDFS.java
@@ -1,7 +1,8 @@
 package net.floodlightcontroller.util;
 
 public class ClusterDFS {
-    long dfsIndex; 
+    long dfsIndex;
+    long parentDfsIndex;
     long lowpoint;
     boolean visited; 
 
@@ -19,6 +20,13 @@ public class ClusterDFS {
         this.dfsIndex = dfsIndex;
     }
 
+    public long getParentDfsIndex() {
+        return parentDfsIndex;
+    }
+
+    public void setParentDfsIndex(long parentDfsIndex) {
+        this.parentDfsIndex = parentDfsIndex;
+    }
     public long getLowpoint() {
         return lowpoint;
     }
@@ -34,4 +42,6 @@ public class ClusterDFS {
     public void setVisited(boolean visited) {
         this.visited = visited;
     }
+
+
 }