diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp
index 12a851f..166b946 100644
--- a/src/V3LinkCells.cpp
+++ b/src/V3LinkCells.cpp
@@ -95,6 +95,7 @@ private:
     V3SymTable  m_mods;		// Symbol table of all module names
     LinkCellsGraph	m_graph;	// Linked graph of all cell interconnects
     LibraryVertex*	m_libVertexp;	// Vertex at root of all libraries
+    V3GraphVertex*	m_topVertexp;	// Vertex of top module
 
     static int debug() {
 	static int level = -1;
@@ -126,12 +127,22 @@ private:
 		vvertexp->modp()->level(vvertexp->rank()+1);
 	    }
 	}
+	if (v3Global.opt.topModule()!=""
+	    && !m_topVertexp) {
+	    v3error("Specified --top-module '"<<v3Global.opt.topModule()<<"' was not found in design.");
+	}
     }
     virtual void visit(AstModule* nodep, AstNUser*) {
 	// Module: Pick up modnames, so we can resolve cells later
 	m_modp = nodep;
 	UINFO(2,"Link Module: "<<nodep<<endl);
-	if (nodep->inLibrary()) {
+	bool topMatch = (v3Global.opt.topModule()==nodep->name());
+	if (topMatch) m_topVertexp = vertex(nodep);
+	if (v3Global.opt.topModule()==""
+	    ? nodep->inLibrary()   // Library cells are lower
+	    : !topMatch) {  // Any non-specified module is lower
+	    // Put under a fake vertex so that the graph ranking won't indicate
+	    // this is a top level module
 	    if (!m_libVertexp) m_libVertexp = new LibraryVertex(&m_graph);
 	    new V3GraphEdge(&m_graph, m_libVertexp, vertex(nodep), 1, false);
 	}
@@ -231,9 +242,9 @@ public:
     LinkCellsVisitor() {
 	m_modp = NULL;
 	m_libVertexp = NULL;
+	m_topVertexp = NULL;
     }
-    virtual ~LinkCellsVisitor() {
-    }
+    virtual ~LinkCellsVisitor() {}
     void main(AstNetlist* rootp) {
 	rootp->accept(*this);
     }
diff --git a/src/V3LinkLevel.cpp b/src/V3LinkLevel.cpp
index 12e96cd..86a25f5 100644
--- a/src/V3LinkLevel.cpp
+++ b/src/V3LinkLevel.cpp
@@ -50,20 +50,6 @@ void V3LinkLevel::modSortByLevel() {
     // Calculate levels again in case we added modules
     UINFO(2,"modSortByLevel()\n");
 
-    if (v3Global.opt.topModule()!="") {
-	bool hit = false;
-	for (AstModule* nodep = v3Global.rootp()->modulesp(); nodep; nodep=nodep->nextp()->castModule()) {
-	    if (nodep->name() == v3Global.opt.topModule()) {
-		hit = true;
-	    } else {
-		nodep->level(3);
-	    }
-	}
-	if (!hit) {
-	    v3error("Specified --top-module '"<<v3Global.opt.topModule()<<"' was not found in design.");
-	}
-    }
-
     // level() was computed for us in V3LinkCells
 
     vector<AstModule*> vec;

