diff --git a/src/vhdldocgen.cpp b/src/vhdldocgen.cpp
index d09de093..74f112b2 100644
--- a/src/vhdldocgen.cpp
+++ b/src/vhdldocgen.cpp
@@ -68,6 +68,12 @@ static QDict<QCString> g_vhdlKeyDict1(17,FALSE);
 static QDict<QCString> g_vhdlKeyDict2(17,FALSE);
 static QDict<QCString> g_vhdlKeyDict3(17,FALSE);
 
+// contains variables/functions of each packages
+static QMap<QCString,MemberDef*> varMap;
+
+//  included packages of each component
+static QMap<ClassDef*,QList<ClassDef> > packages;
+
 static void initUCF(Entry* root,const char* type,QCString &  qcs,int line,QCString & fileName,QCString & brief);
 static void writeUCFLink(const MemberDef* mdef,OutputList &ol);
 static void assignBinding(VhdlConfNode* conf);
@@ -567,9 +573,12 @@ VhdlDocGen::~VhdlDocGen()
 {
 }
 
+
+
+
 void VhdlDocGen::init()
 {
-
+ VhdlDocGen::addAllPackages();
  // vhdl keywords included VHDL 2008
 const char* g_vhdlKeyWordMap0[] =
 {
@@ -699,6 +708,21 @@ ClassDef *VhdlDocGen::getClass(const char *name)
   //temp=temp.lower();
   temp=temp.stripWhiteSpace();
   cd= Doxygen::classSDict->find(temp.data());
+
+ // searching upper/lower case names
+
+    if (!cd)
+    {
+      temp=temp.upper();
+      cd = Doxygen::classSDict->find(temp.data());
+    }
+    if (!cd)
+    {
+      temp=temp.lower();
+      cd = Doxygen::classSDict->find(temp.data());;
+    }
+
+
   return cd;
 }
 
@@ -710,9 +734,128 @@ ClassDef* VhdlDocGen::getPackageName(const QCString & name)
   return cd;
 }
 
-static QMap<QCString,MemberDef*> varMap;
-static QList<ClassDef> qli;
-static QMap<ClassDef*,QList<ClassDef> > packages;
+
+void VhdlDocGen::addAllPackages()
+{
+
+  printf("\n assign variable/functions to classes....\n");
+
+
+  ClassDef *citer;
+
+  ClassSDict::Iterator cli(*Doxygen::classSDict);
+
+  for ( ; (citer=cli.current()) ; ++cli )
+  {
+    if ((VhdlDocGen::VhdlClasses)citer->protection()==VhdlDocGen::ENTITYCLASS ||
+      (VhdlDocGen::VhdlClasses)citer->protection()==VhdlDocGen::PACKAGECLASS)
+        VhdlDocGen::assignVariables(citer);
+  }// for
+ for (cli.toFirst() ; (citer=cli.current()) ; ++cli )
+  {
+
+  if ((VhdlDocGen::VhdlClasses)citer->protection()==VhdlDocGen::ARCHITECTURECLASS ||
+      (VhdlDocGen::VhdlClasses)citer->protection()==VhdlDocGen::PACKBODYCLASS)
+      VhdlDocGen::assignVariables(citer);
+
+  }
+
+}//findAllArchitectures
+
+void VhdlDocGen::assignVariables(ClassDef *citer){
+
+        MemberDef *md=0;
+
+      getAllIncludedPackages(citer);
+      MemberList* ml = citer->getMemberList(MemberListType_variableMembers);
+      if(ml){
+      MemberListIterator fmni(*ml);
+
+      for (fmni.toFirst();(md=fmni.current());++fmni)
+      {
+       QCString tkey=citer->symbolName()+"@"+md->name();
+        varMap.insert(tkey.data(),md);
+    //	printf("\n insert variable %s %s %d: ",citer->symbolName().data(),md->name().data(),varMap.count());
+      }
+      }
+
+       ml = citer->getMemberList(MemberListType_pubMethods);
+       if(ml){
+      MemberListIterator fmni(*ml);
+
+      for (fmni.toFirst();(md=fmni.current());++fmni)
+      {
+       QCString tkey=citer->symbolName()+"@"+md->name();
+        varMap.insert(tkey.data(),md);
+   //  	printf("\n insert function %s %s %d: ",citer->symbolName().data(),md->name().data(),varMap.count());
+      }
+    }
+  }// for
+///////
+
+/*!
+ * finds all included packages of an Entity or Package
+ */
+
+void VhdlDocGen::getAllIncludedPackages(ClassDef *cdef)
+{
+  QList<ClassDef> cList;
+ // if (packages.contains(cdef)) return;
+ // printf("\n searching packes for class %s ",cdef->name().data());
+
+  MemberList *mem=cdef->getMemberList(MemberListType_variableMembers);
+  MemberDef *md;
+
+  if (!mem) return;
+
+  MemberListIterator fmni(*mem);
+  for (fmni.toFirst();(md=fmni.current());++fmni)
+  {
+    if (VhdlDocGen::isPackage(md))
+    {
+      ClassDef* cd=VhdlDocGen::getPackageName(md->name());
+      if (cd)
+      {
+        cList.append(cd);
+ //       printf("\n adding package %s to class %s ",cd->name().data(),cdef->name().data());
+      }
+    }
+  }//for
+
+   if ((VhdlDocGen::VhdlClasses)cdef->protection()==VhdlDocGen::ARCHITECTURECLASS ||
+      (VhdlDocGen::VhdlClasses)cdef->protection()==VhdlDocGen::PACKBODYCLASS)
+  {
+      const char *bb=cdef->name().data();
+
+      ClassDef *cc=0;
+
+        if((VhdlDocGen::VhdlClasses)cdef->protection()==VhdlDocGen::PACKBODYCLASS)
+            cc =getClass(getClassName(cdef));
+        else
+            cc =getClass(getIndexWord(cdef->name().data(),0));
+
+
+     if(cc)
+     {
+     QMap<ClassDef*,QList<ClassDef> >::Iterator cPackList=packages.find(cc);
+
+     if (cPackList.key()!=0)
+	  {
+      QList<ClassDef> mlist=cPackList.data();
+      for (uint j=0;j<mlist.count();j++){
+            ClassDef *mdc=mlist.at(j);
+     //     printf("\n adding package %s to class %s ",mdc->name().data(),cc->name().data());
+        cList.append(mdc);
+      }
+      }
+     }
+  }
+
+  if(cList.count()>0)
+   packages.insert(cdef,cList);
+
+}// findAllPackages
+
 
 MemberDef* VhdlDocGen::findMember(const QCString& className, const QCString& memName)
 {
@@ -723,87 +866,49 @@ MemberDef* VhdlDocGen::findMember(const QCString& className, const QCString& mem
   //printf("VhdlDocGen::findMember(%s,%s)=%p\n",className.data(),memName.data(),cd);
   if (cd==0) return 0;
 
-  mdef=VhdlDocGen::findMemberDef(cd,memName,MemberListType_variableMembers);
-  if (mdef) return mdef;
-  mdef=VhdlDocGen::findMemberDef(cd,memName,MemberListType_pubMethods);
+  mdef=VhdlDocGen::findMemberDef(cd,memName);
   if (mdef) return mdef;
 
+
   // nothing found so far
-  // if we are an architecture or package body search in entity
+  // if we are an architecture or package body search in entity/package
 
   if ((VhdlDocGen::VhdlClasses)cd->protection()==VhdlDocGen::ARCHITECTURECLASS ||
       (VhdlDocGen::VhdlClasses)cd->protection()==VhdlDocGen::PACKBODYCLASS)
   {
     Definition *d = cd->getOuterScope();
-    // searching upper/lower case names
 
-    QCString tt=d->name();
-    ecd =getClass(tt);
-    if (!ecd)
-    {
-      tt=tt.upper();
-      ecd =getClass(tt);
-    }
-    if (!ecd)
-    {
-      tt=tt.lower();
-      ecd =getClass(tt);
-    }
+
+    if((VhdlDocGen::VhdlClasses)cd->protection()==VhdlDocGen::PACKBODYCLASS)
+      ecd =getClass(getClassName(cd));
+     else
+      ecd =getClass(getIndexWord(cd->name().data(),0));
+      //QCString tt1=VhdlDocGen::getIndexWord(cd->name(),0);
+   //  ClassDef *ecd=getClass(tt.data());
+// fprintf(stderr,"\n OUTER %s %s",tt.data(),cd->name().data());
+
+    // assert(ecd);
 
     if (ecd) //d && d->definitionType()==Definition::TypeClass)
     {
-      //ClassDef *ecd = (ClassDef*)d;
-      mdef=VhdlDocGen::findMemberDef(ecd,memName,MemberListType_variableMembers);
+      mdef=VhdlDocGen::findMemberDef(ecd,memName);
       if (mdef) return mdef;
-      mdef=VhdlDocGen::findMemberDef(cd,memName,MemberListType_pubMethods);
-      if (mdef) return mdef;
-    }
+      }
    }
 
 
-  if ((VhdlDocGen::VhdlClasses)cd->protection()==VhdlDocGen::ARCHITECTURECLASS ||
-      (VhdlDocGen::VhdlClasses)cd->protection()==VhdlDocGen::PACKBODYCLASS)
-  {
-    Definition *d = cd->getOuterScope();
+ QMap<ClassDef*,QList<ClassDef> >::Iterator cList=packages.find(cd);
 
-    QCString tt=d->name();
-    ClassDef *ecd =getClass(tt);
-    if (!ecd)
-    {
-      tt=tt.upper();
-      ecd =getClass(tt);
-    }
-    if (!ecd)
-    {
-      tt=tt.lower();
-      ecd =getClass(tt);
-    }
-    if (ecd) //d && d->definitionType()==Definition::TypeClass)
-    {
-      if(!packages.contains(ecd))
-      {
-        VhdlDocGen::findAllPackages(ecd);
-      }
-    }
-  }
-  else
-  {
-    ecd=cd;
-    if (!packages.contains(ecd)) VhdlDocGen::findAllPackages(ecd);
-  }
-
- QMap<ClassDef*,QList<ClassDef> >::Iterator cList=packages.find(ecd);
       if (cList.key()!=0)
 	  {
       QList<ClassDef> mlist=cList.data();
       for (uint j=0;j<mlist.count();j++)
       {
-        mdef=VhdlDocGen::findMemberDef(mlist.at(j),memName,MemberListType_variableMembers);
-        if (mdef) return mdef;
-        mdef=VhdlDocGen::findMemberDef(mlist.at(j),memName,MemberListType_pubMethods);
+        mdef=VhdlDocGen::findMemberDef(mlist.at(j),memName);
         if (mdef) return mdef;
-      }
+       }
 	  }
+
   return 0;
 
 }//findMember
@@ -812,86 +917,35 @@ MemberDef* VhdlDocGen::findMember(const QCString& className, const QCString& mem
  *  This function returns the entity|package
  *  in which the key (type) is found
  */
-MemberDef* VhdlDocGen::findMemberDef(ClassDef* cd,const QCString& key,MemberListType type)
+MemberDef* VhdlDocGen::findMemberDef(ClassDef* cd,const QCString& key)
 {
   MemberDef *md=0;
-  MemberList *ml=0;
-  QCString keyType=cd->symbolName()+"@"+key;
-  //printf("\n %s | %s | %s",cd->symbolName().data(),key.data(,),keyType.data());
 
-  QMap<QCString, MemberDef*>::Iterator it =varMap.find(keyType);
-  if (it.key())
-  {
-    md=it.data();
-    if (md)
-    {
-      return md;
-    }
-  }
-  if (qli.contains(cd))
-  {
-    return 0;
-  }
-  ml=cd->getMemberList(type);
-  qli.append(cd);
-  if (!ml)
-  {
-    return 0;
-  }
-  MemberListIterator fmni(*ml);
-  //int l=ml->count();
-  //	fprintf(stderr,"\n loading entity %s %s: %d",cd->symbolName().data(),keyType.data(),l);
+   if(key.isEmpty())
+   return 0;
 
-  for (fmni.toFirst();(md=fmni.current());++fmni)
-  {
-    QCString tkey=cd->symbolName()+"@"+md->name();
-    if (varMap.contains(tkey))
-    {
-      continue;
-    }
-    varMap.insert(tkey.data(),md);
-  }
-  it=varMap.find(keyType.data());
-  if (it.key())
-  {
-    md=it.data();
-    if (md)
-    {
-      return md;
-    }
-  }
-  return 0;
-}//findMemberDef
+// start _a-zA-Z
+   char c=key.at(0);
+   if( !isalpha(c))
+   {
+    if(c!='_')
+     return 0;
+   }
 
-/*!
- * finds all included packages of an Entity or Package
- */
+     QCString keyType=cd->symbolName()+"@"+key;
+     QMap<QCString, MemberDef*>::Iterator it =varMap.find(keyType);
+     it=varMap.find(keyType.data());
 
-void VhdlDocGen::findAllPackages( ClassDef *cdef)
-{
-  QList<ClassDef> cList;
-  if (packages.contains(cdef)) return;
-  MemberList *mem=cdef->getMemberList(MemberListType_variableMembers);
-  MemberDef *md;
+     if (it.key())
+     {
+        return it.data();
+     }
+
+  return 0;
+}//findMemberDef
 
-  if (!mem) return;
 
-  MemberListIterator fmni(*mem);
-  for (fmni.toFirst();(md=fmni.current());++fmni)
-  {
-    if (VhdlDocGen::isPackage(md))
-    {
-      ClassDef* cd=VhdlDocGen::getPackageName(md->name());
-      if (cd)
-      {
-        cList.append(cd);
-        VhdlDocGen::findAllPackages(cd);
-        packages.insert(cdef,cList);
-      }
-    }
-  }//for
 
-}// findAllPackages
 
 /*!
  * returns the function with the matching argument list
@@ -3350,8 +3404,7 @@ void VhdlDocGen::createFlowChart(const MemberDef *mdef)
 void VhdlDocGen::resetCodeVhdlParserState()
 {
   varMap.clear();
-  qli.clear();
-  packages.clear();
+   packages.clear();
 }
 
 bool VhdlDocGen::isConstraint(const MemberDef *mdef)
diff --git a/src/vhdldocgen.h b/src/vhdldocgen.h
index bd190ca1..1233bc07 100644
--- a/src/vhdldocgen.h
+++ b/src/vhdldocgen.h
@@ -3,8 +3,8 @@
  * Copyright (C) 1997-2015 by Dimitri van Heesch.
  *
  * Permission to use, copy, modify, and distribute this software and its
- * documentation under the terms of the GNU General Public License is hereby 
- * granted. No representations are made about the suitability of this software 
+ * documentation under the terms of the GNU General Public License is hereby
+ * granted. No representations are made about the suitability of this software
  * for any purpose. It is provided "as is" without express or implied warranty.
  * See the GNU General Public License for more details.
  *
@@ -16,8 +16,8 @@
 #ifndef VHDLDOCGEN_H
 #define VHDLDOCGEN_H
 
-/** 
- * This class implements functions for parsing and generating 
+/**
+ * This class implements functions for parsing and generating
  * vhdl documents
  */
 
@@ -40,7 +40,7 @@ class NamespaceDef;
 struct Argument;
 
 /** Class for generating documentation specific for VHDL */
-class VhdlDocGen  
+class VhdlDocGen
 {
   public:
 
@@ -71,11 +71,11 @@ class VhdlDocGen
       USE,
       PROCESS,
       PORT,
-      UNITS,	  
+      UNITS,
       GENERIC,
       INSTANTIATION,
       GROUP,
-      VFILE,   
+      VFILE,
       SHAREDVARIABLE,
       CONFIG,
       ALIAS,
@@ -88,30 +88,30 @@ class VhdlDocGen
     static void init();
     static QCString convertFileNameToClassName(QCString name);
     // --- used by vhdlscanner.l -----------
-    
+
     static bool isSubClass(ClassDef* cd,ClassDef *scd, bool followInstances,int level);
 
     static QCString getIndexWord(const char* ,int index);
     static bool     deleteCharRev(QCString &s,char c);
     static void     deleteAllChars(QCString &s,char c);
     static void     parseFuncProto(const char* text,
-                                   QList<Argument>& , 
+                                   QList<Argument>& ,
                                    QCString& name,
                                    QCString& ret,
                                    bool doc=false);
     // -----------------------------------
 
     static void computeVhdlComponentRelations();
-
+    static void addAllPackages();
+    static void assignVariables( ClassDef *citer);
     static QCString* findKeyWord(const QCString& word);
 
     static ClassDef* getPackageName(const QCString& name);
-    static MemberDef* findMember(const QCString& className, 
+    static MemberDef*findMember(const QCString& className,
                                  const QCString& memName);
-    static void findAllPackages(ClassDef*);
+    static void getAllIncludedPackages(ClassDef* cd);
     static MemberDef* findMemberDef(ClassDef* cd,
-                                const QCString& key,
-                                MemberListType type);
+                                const QCString& key);
     static ClassDef *getClass(const char *name);
     static MemberDef* findFunction(const QList<Argument> &ql,
                                    const QCString& name,
@@ -151,7 +151,7 @@ class VhdlDocGen
 
     //-----------------------------------------------------
     // translatable items
-    
+
     static QCString trTypeString(uint64 type);
     static QCString trVhdlType(uint64 type,bool sing=true);
 
@@ -208,7 +208,7 @@ class VhdlDocGen
     static QCString convertArgumentListToString(const ArgumentList* al,bool f);
     static QCString getProcessNumber();
     static QCString getRecordNumber();
-   
+
     static QCString getClassName(const ClassDef*);
     static bool isNumber(const QCString& s);
     static QCString getProtectionName(int prot);
@@ -219,7 +219,7 @@ class VhdlDocGen
     static ClassDef*  findArchitecture(const ClassDef *cd);
     static ClassDef*  findArchitecture(QCString identifier, QCString entity_name);
 
-    
+
     static void writeSource(MemberDef *mdef,OutputList& ol,QCString & cname);
     static void writeAlphbeticalClass(OutputList& ol,const ClassDef* cd,const QCString &);
 
@@ -230,15 +230,15 @@ class VhdlDocGen
 
     static void writeOverview(OutputList &ol);
     static void writeOverview();
- 
+
  // flowcharts
     static void createFlowChart(const MemberDef*);
     //static void addFlowImage(const FTextStream &,const QCString &);
-    
+
     static void setFlowMember( const MemberDef *flowMember);
     static const MemberDef *getFlowMember();
 
-    static  bool isVhdlClass (const Entry *cu) 
+    static  bool isVhdlClass (const Entry *cu)
     {
       return cu->spec==VhdlDocGen::ENTITY       ||
              cu->spec==VhdlDocGen::PACKAGE      ||
@@ -291,7 +291,7 @@ class FlowChart
       BEGIN_NO     = 1<<21
     };
 
-    //---------- create svg ------------------------------------------------------------- 
+    //---------- create svg -------------------------------------------------------------
     static void createSVG();
     static void startDot(FTextStream &t);
     static void endDot(FTextStream &t);
