diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/http_www_example_org_correct_ref_and_type_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/http_www_example_org_correct_ref_and_type_e.ttcn
new file mode 100644
index 0000000000000000000000000000000000000000..96cd7d06ae97383ff66194cef635273487735ac1
--- /dev/null
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/http_www_example_org_correct_ref_and_type_e.ttcn
@@ -0,0 +1,249 @@
+/*******************************************************************************
+* Copyright (c) 2000-2017 Ericsson Telecom AB
+*
+* XSD to TTCN-3 Translator
+*
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+*   Balasko, Jeno
+*   Szabo, Bence Janos
+*
+******************************************************************************/
+//
+//  File:          http_www_example_org_correct_ref_and_type.ttcn
+//  Description:
+//  References:
+//  Rev:
+//  Prodnr:
+//  Updated:       Wed Sep  6 13:38:35 2017
+//  Contact:       http://ttcn.ericsson.se
+//
+////////////////////////////////////////////////////////////////////////////////
+//	Generated from file(s):
+//	- correct_ref_and_type.xsd
+//			/* xml version = "1.0" encoding = "UTF-8" */
+//			/* targetnamespace = "http://www.example.org/correct/ref/and/type" */
+////////////////////////////////////////////////////////////////////////////////
+//     Modification header(s):
+//-----------------------------------------------------------------------------
+//  Modified by:
+//  Modification date:
+//  Description:
+//  Modification contact:
+//------------------------------------------------------------------------------
+////////////////////////////////////////////////////////////////////////////////
+
+
+module http_www_example_org_correct_ref_and_type {
+
+
+import from XSD all;
+
+
+type record A_3
+{
+	XSD.AnySimpleType aGroup
+}
+with {
+  variant "untagged";
+};
+
+
+type record B_2
+{
+	XSD.AnySimpleType bGroup,
+	XSD.AnySimpleType aGroup
+}
+with {
+  variant "untagged";
+};
+
+
+type record B_1
+{
+	A_2 baseAttr optional,
+	XSD.String baseElem
+}
+with {
+  variant "name as 'B'";
+  variant (baseAttr) "attribute";
+};
+
+
+type XSD.Integer A_1
+with {
+  variant "name as 'A'";
+  variant "attribute";
+};
+
+
+type XSD.Integer B
+with {
+  variant "attribute";
+};
+
+
+type XSD.Integer C
+with {
+  variant "attribute";
+};
+
+
+type XSD.Integer A
+with {
+  variant "element";
+};
+
+
+type enumerated A_2
+{
+	simpleType,
+	simpleType1
+}
+with {
+  variant "text 'simpleType' as capitalized";
+  variant "text 'simpleType1' as capitalized";
+  variant "name as 'A'";
+};
+
+
+type union C_1
+{
+	XSD.Integer alt_,
+	XSD.String alt_1
+}
+with {
+  variant "name as 'C'";
+  variant "useUnion";
+  variant (alt_) "name as ''";
+  variant (alt_1) "name as ''";
+};
+
+
+type record Element
+{
+	A_1 a optional,
+	XSD.Integer attr optional,
+	B b optional,
+	A_2 simpleTypeAttr optional,
+	C_1 simpleTypeAttr2 optional,
+	A a_1,
+	A_2 simpleTypeRef,
+	B_1 complexTypeRef,
+	XSD.AnySimpleType bGroup,
+	XSD.AnySimpleType aGroup
+}
+with {
+  variant "element";
+  variant (a) "name as capitalized";
+  variant (a) "attribute";
+  variant (attr) "name as capitalized";
+  variant (attr) "attribute";
+  variant (b) "name as capitalized";
+  variant (b) "attribute";
+  variant (simpleTypeAttr) "name as capitalized";
+  variant (simpleTypeAttr) "attribute";
+  variant (simpleTypeAttr2) "name as capitalized";
+  variant (simpleTypeAttr2) "attribute";
+  variant (a_1) "name as 'A'";
+  variant (simpleTypeRef) "name as capitalized";
+  variant (complexTypeRef) "name as capitalized";
+};
+
+
+type enumerated AExtension
+{
+	simpleType
+}
+with {
+  variant "text 'simpleType' as capitalized";
+};
+
+
+type A_2 AType
+with {
+  variant "element";
+};
+
+
+type A_2 AAttr
+with {
+  variant "attribute";
+};
+
+
+type B_1 BType
+with {
+  variant "element";
+};
+
+
+type B_1 BAttr
+with {
+  variant "attribute";
+};
+
+
+type record SimpleTypExtension
+{
+	XSD.Integer attr optional,
+	A_2 base
+}
+with {
+  variant (attr) "attribute";
+  variant (base) "untagged";
+};
+
+
+type record SimpleTypeRestriction
+{
+	enumerated {
+		simpleType
+	} base
+}
+with {
+  variant (base) "untagged";
+  variant (base) "text 'simpleType' as capitalized";
+};
+
+
+type record ComplexTypeExtension
+{
+	A_2 extattr optional,
+	A_2 baseAttr optional,
+	XSD.String baseElem,
+	XSD.Integer extelem
+}
+with {
+  variant (extattr) "name as capitalized";
+  variant (extattr) "attribute";
+  variant (baseAttr) "attribute";
+  variant (extelem) "name as capitalized";
+};
+
+
+type record ComplexTypeRestriction
+{
+	XSD.String baseElem
+};
+
+
+type record ComplexTypeGroup
+{
+	record length(1 .. 4) of B_2 b_list
+}
+with {
+  variant (b_list) "untagged";
+};
+
+
+}
+with {
+  encode "XML";
+  variant "namespace as 'http://www.example.org/correct/ref/and/type' prefix 'this'";
+  variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
+}
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/name_conversion_extension_attrib_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/name_conversion_extension_attrib_e.ttcn
index 37ec787b9215ba40e940ce2fba2fd710e58ee3eb..a4abfff51521e775270eb44da5ba7d4d07623890 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/name_conversion_extension_attrib_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/name_conversion_extension_attrib_e.ttcn
@@ -44,23 +44,35 @@ module name_conversion_extension_attrib {
 import from XSD all;
 
 
-type record Ol_name_type
+type Ol_name_type_type Ol_name_type
+with {
+  variant "name as 'Ol-name-type'";
+  variant "element";
+};
+
+
+type record Ol_name_type_type
 {
 	XSD.Integer allow_true_action
 }
 with {
-  variant "name as 'Ol-name-type'";
-  variant "element";
+  variant "name as 'Ol-name-type_type'";
   variant (allow_true_action) "name as 'allow-true-action'";
 };
 
 
+type XSD.String Attr
+with {
+  variant "attribute";
+};
+
+
 type record Ol_actions_type
 {
 	XSD.Integer do_not_disturb,
 	record {
-		Ol_name_type announcement_name,
-		Ol_name_type content optional
+		Attr attr,
+		Ol_name_type_type content optional
 	} play_segmented_announcement
 }
 with {
@@ -69,8 +81,8 @@ with {
   variant (do_not_disturb) "name as 'do-not-disturb'";
   variant (play_segmented_announcement) "name as 'play-segmented-announcement'";
   variant (play_segmented_announcement) "useNil";
-  variant (play_segmented_announcement.announcement_name) "name as 'announcement-name'";
-  variant (play_segmented_announcement.announcement_name) "attribute";
+  variant (play_segmented_announcement.attr) "name as capitalized";
+  variant (play_segmented_announcement.attr) "attribute";
 };
 
 
@@ -78,7 +90,7 @@ type record Ol_actions_type2
 {
 	XSD.Integer do_not_disturb,
 	record {
-		Ol_name_type announcement_name,
+		Attr attr,
 		record {
 			XSD.Integer allow_true_action,
 			XSD.String elem
@@ -91,8 +103,8 @@ with {
   variant (do_not_disturb) "name as 'do-not-disturb'";
   variant (play_segmented_announcement) "name as 'play-segmented-announcement'";
   variant (play_segmented_announcement) "useNil";
-  variant (play_segmented_announcement.announcement_name) "name as 'announcement-name'";
-  variant (play_segmented_announcement.announcement_name) "attribute";
+  variant (play_segmented_announcement.attr) "name as capitalized";
+  variant (play_segmented_announcement.attr) "attribute";
   variant (play_segmented_announcement.content.allow_true_action) "name as 'allow-true-action'";
 };
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_complex_import_AB_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_complex_import_AB_e.ttcn
index bd5dd1fda43971da3030d8cea9ea7d80d429a74e..04a6aa4f3c376d57e6adbd54c38ee1b48c9d344e 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_complex_import_AB_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_complex_import_AB_e.ttcn
@@ -63,12 +63,16 @@ import from www_XmlTest_org_complex_import_B all;
 
 type record PurchaseReportImport
 {
-	www_XmlTest_org_complex_import_A.MyType myTypeA,
-	www_XmlTest_org_complex_import_B.MyType myTypeB
+	www_XmlTest_org_complex_import_A.MyType myType,
+	www_XmlTest_org_complex_import_B.MyType myType_1
 }
 with {
   variant "name as uncapitalized";
   variant "element";
+  variant (myType) "name as capitalized";
+  variant (myType) "namespace as 'www.XmlTest.org/complex_import_A' prefix 'A'";
+  variant (myType_1) "name as 'MyType'";
+  variant (myType_1) "namespace as 'www.XmlTest.org/complex_import_B' prefix 'B'";
 };
 
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn
index c96ae3b9ddccbcca96c4cf6adc5ae56333d98b78..485d71206fa3905835eb7cea5940db591774f061 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_XmlTest_org_string_e.ttcn
@@ -92,7 +92,7 @@ with {
 };
 
 
-type Non_empty_string Non_empty_stringChild length(0 .. infinity)
+type XSD.String Non_empty_stringChild length(3)
 with {
   variant "name as 'Non-empty-stringChild'";
 };
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_all_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_all_e.ttcn
index 7361944df5ea4732f501d74705bf15b21f11ba56..45a04ca9fa82ed92287cde0bf387986907e9b107 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_all_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_all_e.ttcn
@@ -66,8 +66,8 @@ type record E29a
 	XSD.String ding
 }
 with {
-  variant "name as uncapitalized";
   variant "useOrder";
+  variant "untagged";
 };
 
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_anyattrib_single_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_anyattrib_single_e.ttcn
index 8ce695193bd73b76e76cb1dfd3bc94a98fffb815..9c92cef6d7ceb0b8efda34dcf7cafa316e986d75 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_anyattrib_single_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_anyattrib_single_e.ttcn
@@ -57,18 +57,24 @@ with {
   variant "name as uncapitalized";
   variant (attrInGroup1) "attribute";
   variant (attrInGroup2) "attribute";
-  variant (attr) "anyAttributes from 'http://www.w3.org/1999/xhtml','www.example.org/anyattrib/single','www.example.org/anyattrib/single'";
+  variant (attr) "anyAttributes from 'http://www.w3.org/1999/xhtml', 'www.example.org/anyattrib/single', 'www.example.org/anyattrib/single'";
 };
 
 
-type record E45c
+type E45c_type E45c
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type record E45c_type
 {
 	record of XSD.String attr optional
 }
 with {
   variant "name as uncapitalized";
-  variant "element";
-  variant (attr) "anyAttributes from unqualified,'http://www.example.org/attribute'";
+  variant (attr) "anyAttributes from unqualified, 'http://www.example.org/attribute'";
 };
 
 
@@ -79,7 +85,7 @@ type record E45d
 with {
   variant "name as uncapitalized";
   variant "element";
-  variant (attr) "anyAttributes from 'www.example.org/anyattrib/single',unqualified,'http://www.example.org/attribute'";
+  variant (attr) "anyAttributes from 'www.example.org/anyattrib/single', unqualified, 'http://www.example.org/attribute'";
 };
 
 
@@ -125,7 +131,7 @@ type record MyType2
 with {
   variant "element";
   variant (ding) "attribute";
-  variant (attr) "anyAttributes from 'www.example.org/anyattrib/single',unqualified, 'www.example.org/anyattrib/single'";
+  variant (attr) "anyAttributes from 'www.example.org/anyattrib/single', unqualified, 'www.example.org/anyattrib/single'";
 };
 
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_attr_ext_rest_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_attr_ext_rest_e.ttcn
index e5678cd8f95d5ffb201333796de21bd902705fa0..e93a7e822d99e462cc5ce11f2de69ec57ba4a0b8 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_attr_ext_rest_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_attr_ext_rest_e.ttcn
@@ -99,16 +99,9 @@ with {
 };
 
 
-type record E25seqd
-{
-	XSD.Integer gender optional,
-	XSD.Integer genderAttrBase,
-	XSD.Integer ageElemExt
-}
+type E25seqc E25seqd
 with {
   variant "name as uncapitalized";
-  variant (gender) "attribute";
-  variant (genderAttrBase) "attribute";
 };
 
 
@@ -147,7 +140,14 @@ with {
 };
 
 
-type record E23
+type E23_type E23
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type record E23_type
 {
 	XSD.Integer bar optional,
 	XSD.Integer base optional,
@@ -156,7 +156,6 @@ type record E23
 }
 with {
   variant "name as uncapitalized";
-  variant "element";
   variant (bar) "attribute";
   variant (base) "attribute";
   variant (foo) "attribute";
@@ -165,7 +164,14 @@ with {
 };
 
 
-type record E24
+type E24_type E24
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type record E24_type
 {
 	XSD.Integer bar optional,
 	XSD.Integer base optional,
@@ -175,7 +181,6 @@ type record E24
 }
 with {
   variant "name as uncapitalized";
-  variant "element";
   variant (bar) "attribute";
   variant (base) "attribute";
   variant (foo) "attribute";
@@ -185,7 +190,14 @@ with {
 };
 
 
-type record E25
+type E25_type E25
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type record E25_type
 {
 	XSD.Integer bar optional,
 	XSD.Integer goo,
@@ -193,7 +205,6 @@ type record E25
 }
 with {
   variant "name as uncapitalized";
-  variant "element";
   variant (bar) "attribute";
   variant (goo) "attribute";
   variant (base) "untagged";
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_dont_generate_element_substitution_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_dont_generate_element_substitution_e.ttcn
index f6b591eb2b08890d1947b468a4d141c775a28de7..69572a664d102842e88228bcdaf0fa4fe6c3a960 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_dont_generate_element_substitution_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_dont_generate_element_substitution_e.ttcn
@@ -51,7 +51,14 @@ with {
 };
 
 
-type record ComplexEnum
+type ComplexEnum_type ComplexEnum
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type record ComplexEnum_type
 {
 	XSD.Integer bar optional,
 	XSD.Float foo optional,
@@ -59,7 +66,6 @@ type record ComplexEnum
 }
 with {
   variant "name as uncapitalized";
-  variant "element";
   variant (bar) "attribute";
   variant (foo) "attribute";
   variant (base) "untagged";
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn
index 1ef6eb34df64bd0cbec1ebdf31150b0a66c178b0..2f47ea7788f0f54724dd42ee3b6dbc8f569cd0ef 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn
@@ -44,7 +44,14 @@ module www_example_org_enumeration_restriction {
 import from XSD all;
 
 
-type union E21unnamed
+type E21unnamed_type E21unnamed
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type union E21unnamed_type
 {
 	XSD.Integer alt_,
 	XSD.Float alt_1,
@@ -53,14 +60,13 @@ type union E21unnamed
 with {
   variant "name as uncapitalized";
   variant "useUnion";
-  variant "element";
   variant (alt_) "name as ''";
   variant (alt_1) "name as ''";
   variant (alt_2) "name as ''";
 };
 
 
-type E21unnamed E22 (
+type E21unnamed_type E22 (
 	{alt_1:=20.400000},
 	{alt_2:="small"},
 	{alt_:=50}
@@ -70,27 +76,38 @@ with {
 };
 
 
-type union String_int
+type String_int_type String_int
+with {
+  variant "element";
+};
+
+
+type union String_int_type
 {
 	XSD.String alt_,
 	XSD.Integer alt_1
 }
 with {
   variant "useUnion";
-  variant "element";
   variant (alt_) "name as ''";
   variant (alt_1) "name as ''";
 };
 
 
-type String_int Everything_is_string (
+type String_int_type Everything_is_string (
 	{alt_:="20.4"},
 	{alt_:="50"},
 	{alt_:="small"}
 );
 
 
-type union Mixed_Types
+type Mixed_Types_type Mixed_Types
+with {
+  variant "element";
+};
+
+
+type union Mixed_Types_type
 {
 	XSD.GDay alt_,
 	XSD.GYear alt_1,
@@ -106,7 +123,6 @@ type union Mixed_Types
 }
 with {
   variant "useUnion";
-  variant "element";
   variant (alt_) "name as ''";
   variant (alt_1) "name as ''";
   variant (alt_2) "name as ''";
@@ -121,7 +137,7 @@ with {
 };
 
 
-type Mixed_Types Mixed_Enum (
+type Mixed_Types_type Mixed_Enum (
 	{alt_10:="small"},
 	{alt_10:="somestring"},
 	{alt_1:="0085"},
@@ -138,18 +154,23 @@ type Mixed_Types Mixed_Enum (
 );
 
 
-type union Only_int
+type Only_int_type Only_int
+with {
+  variant "element";
+};
+
+
+type union Only_int_type
 {
 	XSD.Integer alt_
 }
 with {
   variant "useUnion";
-  variant "element";
   variant (alt_) "name as ''";
 };
 
 
-type Only_int Ints (
+type Only_int_type Ints (
 	{alt_:=14}
 );
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_generate_element_substitution_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_generate_element_substitution_e.ttcn
index f0c9662e66524f9b78d2b11194bfd7b1b2eaa927..9dcde09c1dd5d53aec2b7d7889c55bcfaa029bbe 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_generate_element_substitution_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_generate_element_substitution_e.ttcn
@@ -44,7 +44,14 @@ module www_example_org_generate_element_substitution {
 import from XSD all;
 
 
-type record ComplexEnum
+type ComplexEnum_type ComplexEnum
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type record ComplexEnum_type
 {
 	XSD.Integer bar optional,
 	XSD.Float foo optional,
@@ -52,7 +59,6 @@ type record ComplexEnum
 }
 with {
   variant "name as uncapitalized";
-  variant "element";
   variant (bar) "attribute";
   variant (foo) "attribute";
   variant (base) "untagged";
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_imported2_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_imported2_e.ttcn
index d354904a139b7328c4217a7dc9eccb39a9acd149..9660c341756c843d6db919c7facd48874c88a5a0 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_imported2_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_imported2_e.ttcn
@@ -50,25 +50,38 @@ with {
 };
 
 
+type Foobar FoobarElem
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
 type XSD.Integer Ding
 with {
   variant "name as uncapitalized";
 };
 
 
-type record Bar
+type Bar_type Bar
+with {
+  variant "name as uncapitalized";
+  variant "element";
+};
+
+
+type record Bar_type
 {
 	XSD.String something optional
 }
 with {
   variant "name as uncapitalized";
-  variant "element";
 };
 
 
 }
 with {
   encode "XML";
-  variant "namespace as 'www.example.org/imported2'";
+  variant "namespace as 'www.example.org/imported2' prefix 'this'";
   variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
 }
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_namespaceas_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_namespaceas_e.ttcn
index 055bdf2c64a593e186a7937afdce41d3fc06cc12..128b470e59f2c963002f7ac929e9dcdb8bf21583 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_namespaceas_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_namespaceas_e.ttcn
@@ -56,11 +56,11 @@ with {
 type record Type
 {
 	Foobar something optional,
-	Foobar foobar
+	FoobarElem foobarElem
 }
 with {
   variant "element";
-  variant (foobar) "namespace as 'www.example.org/imported2' prefix 'other'";
+  variant (foobarElem) "namespace as 'www.example.org/imported2' prefix 'other'";
 };
 
 
@@ -68,8 +68,8 @@ type record OtherType
 {
 	Foobar billingAccountNumber,
 	Foobar something,
-	Bar something2,
-	Bar something3,
+	Bar_type something2,
+	Bar_type something3,
 	record {
 		XSD.String something
 	} something4
@@ -77,7 +77,6 @@ type record OtherType
 with {
   variant (billingAccountNumber) "namespace as 'www.example.org/imported2' prefix 'other'";
   variant (something) "namespace as 'www.example.org/imported2' prefix 'other'";
-  variant (something2) "namespace as 'www.example.org/imported2' prefix 'other'";
 };
 
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_only_element_substitution_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_only_element_substitution_e.ttcn
index 5aeb5fe90eb630ca58461f82a40bb5700df4ffb2..234af35ee19e0231d2cdff8e5e214600ea36e7b6 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_only_element_substitution_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_only_element_substitution_e.ttcn
@@ -44,11 +44,13 @@ module www_example_org_only_element_substitution {
 import from XSD all;
 
 
-type RequestAbstractType_group RequestAbstractType1
+type record RequestAbstractType
+{
+	XSD.String commonName
+}
 with {
   variant "name as uncapitalized";
   variant "abstract";
-  variant "element";
 };
 
 
@@ -80,18 +82,28 @@ with {
 };
 
 
-type union RequestAbstractType_group
+type record Ize
+{
+	record of RequestAbstractType1_group requestAbstractType1_list
+}
+with {
+  variant "name as uncapitalized";
+  variant "element";
+  variant (requestAbstractType1_list) "untagged";
+  variant (requestAbstractType1_list[-]) "name as 'requestAbstractType1'";
+};
+
+
+type union RequestAbstractType1_group
 {
-	record {
-		XSD.String commonName
-	} requestAbstractType,
+	RequestAbstractType requestAbstractType1,
 	ProductionRequest productionRequest,
 	ProgrammingRequest programmingRequest
 }
 with {
   variant "untagged";
-  variant (requestAbstractType) "form as qualified";
-  variant (requestAbstractType) "abstract";
+  variant (requestAbstractType1) "form as qualified";
+  variant (requestAbstractType1) "abstract";
 };
 
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref1_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref1_e.ttcn
index 9a918521b16de5eed0b2f0fc4d6800655ca443bb..52d98450db525174a3188ff5a158f91e4b3c363e 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref1_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref1_e.ttcn
@@ -51,36 +51,36 @@ import from www_example_org_pref3 all;
 
 type record MyElement_2
 {
-	www_example_org_pref2.MyElement myElement optional,
-	www_example_org_pref2.MyElement2 myElement2 optional,
+	MyAttribute myAttribute optional,
+	MyAttribute2 myAttribute2 optional,
 	XSD.Integer myField,
 	www_example_org_pref2.MyType myField2,
-	www_example_org_pref2.MyElement myElement_1,
-	www_example_org_pref2.MyElement2 myElement2_1
+	www_example_org_pref2.MyElement myElement,
+	www_example_org_pref2.MyElement2 myElement2
 }
 with {
   variant "name as 'MyElement'";
   variant "element";
+  variant (myAttribute) "name as capitalized";
+  variant (myAttribute) "namespace as 'www.example.org/pref2' prefix 'ns2'";
+  variant (myAttribute) "attribute";
+  variant (myAttribute2) "name as capitalized";
+  variant (myAttribute2) "namespace as 'www.example.org/pref2' prefix 'ns2'";
+  variant (myAttribute2) "attribute";
   variant (myElement) "name as capitalized";
   variant (myElement) "namespace as 'www.example.org/pref2' prefix 'ns2'";
-  variant (myElement) "attribute";
   variant (myElement2) "name as capitalized";
   variant (myElement2) "namespace as 'www.example.org/pref2' prefix 'ns2'";
-  variant (myElement2) "attribute";
-  variant (myElement_1) "name as 'MyElement'";
-  variant (myElement_1) "namespace as 'www.example.org/pref2' prefix 'ns2'";
-  variant (myElement2_1) "name as 'MyElement2'";
-  variant (myElement2_1) "namespace as 'www.example.org/pref2' prefix 'ns2'";
 };
 
 
-type www_example_org_pref2.MyElement MyElement
+type www_example_org_pref2.MyType MyElement
 with {
   variant "element";
 };
 
 
-type www_example_org_pref2.MyElement2 MyElement_1
+type www_example_org_pref2.MyType MyElement_1
 with {
   variant "name as 'MyElement'";
   variant "element";
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref2_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref2_e.ttcn
index 4395fbf8f1e1694e767953ceb11ed4fe5f0743b7..f64fbcabf89a7aeda0bf99a2fd3b428f3c0a8ce4 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref2_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_pref2_e.ttcn
@@ -55,6 +55,18 @@ with {
 };
 
 
+type MyType MyAttribute
+with {
+  variant "attribute";
+};
+
+
+type MyType MyAttribute2
+with {
+  variant "attribute";
+};
+
+
 type record MyType
 {
 	XSD.Integer myField
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_aliases_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_aliases_e.ttcn
index 55a5f24cb13f649b60a977080e973dd51b20815c..22e6e8c9a7c8dac565619767baec1cac009ec35f 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_aliases_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_aliases_e.ttcn
@@ -212,7 +212,7 @@ type record ComplexSimpleNotAlias_1
 {
 	XSD.String attrgroup1 optional,
 	XSD.String attrgroup2 optional,
-	XSD.String base length(4 .. infinity)
+	Length_1 base length(4 .. infinity)
 }
 with {
   variant "name as 'ComplexSimpleNotAlias'";
@@ -231,7 +231,7 @@ type LengthAlias2 ComplexSimpleAlias2;
 type record ComplexSimpleNotAlias2
 {
 	XSD.String attr optional,
-	XSD.String base length(4 .. infinity)
+	Length_1 base length(4 .. infinity)
 }
 with {
   variant (attr) "attribute";
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn
index f1d8f2fe41867e5af378599048a1708a3b3cca50..4e2d7f883ace7569b29189d8448dd7dfd0dcd3d3 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_simpletype_ref_e.ttcn
@@ -44,27 +44,33 @@ module www_example_org_simpletype_ref {
 import from XSD all;
 
 
-type record SomeType
+type SomeType_type SomeType
+with {
+  variant "element";
+};
+
+
+type record SomeType_type
 {
 	XSD.String something
-}
+};
+
+
+type Type_type Type
 with {
   variant "element";
 };
 
 
-type record Type
+type record Type_type
 {
 	XSD.String something optional
-}
-with {
-  variant "element";
 };
 
 
 type record OtherType
 {
-	SomeType billingAccountNumber,
+	SomeType_type billingAccountNumber,
 	XSD.Long installmentPlanId (-99999 .. 99999),
 	XSD.String info length(0 .. 30) optional
 };
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_complex_without_element_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_complex_without_element_e.ttcn
index b4941eed37b45890ab07ff3ffaa6980b311eaecd..d52fe20686e0c7a9e9202474c40c3c2198975b49 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_complex_without_element_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_complex_without_element_e.ttcn
@@ -50,22 +50,35 @@ with {
 };
 
 
-type XSD.String Member
+type Head_type Member
 with {
   variant "name as uncapitalized";
   variant "element";
 };
 
 
-type enumerated StringEnum
+type record StringEnum
 {
-	else_,
-	something
+	XSD.String headAttrib,
+	XSD.String something
 }
 with {
-  variant "text 'else_' as 'else'";
   variant "name as uncapitalized";
   variant "element";
+  variant (headAttrib) "attribute";
+  variant (something) "name as capitalized";
+};
+
+
+type record Head_type
+{
+	XSD.String headAttrib optional,
+	XSD.String something
+}
+with {
+  variant "name as uncapitalized";
+  variant (headAttrib) "attribute";
+  variant (something) "name as capitalized";
 };
 
 
@@ -105,10 +118,7 @@ with {
 
 type union Head_group_1
 {
-	record {
-		XSD.String headAttrib optional,
-		XSD.String something
-	} head,
+	Head_type head,
 	Member member,
 	Member2 member2,
 	StringEnum stringEnum
@@ -117,8 +127,6 @@ with {
   variant "untagged";
   variant (head) "form as qualified";
   variant (head) "abstract";
-  variant (head.headAttrib) "attribute";
-  variant (head.something) "name as capitalized";
   variant (member) "block";
   variant (member2) "block";
   variant (stringEnum) "block";
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_e.ttcn
index cb5f6efb058f3e1dc7d89e564cd15add8771103a..0382445805e8f9b92660518ce745cea404754a9f 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_e.ttcn
@@ -44,6 +44,16 @@ module www_example_org_substitutiongroup {
 import from XSD all;
 
 
+/* TEST IF THE ELEMENT REFERENCE IS FOUND */
+
+
+type XSD.Integer Head
+with {
+  variant "name as uncapitalized";
+  variant "attribute";
+};
+
+
 /* THE HEAD ELEMENT */
 
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_main_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_main_e.ttcn
index 61702689172b912f2a8701fbc9e2949ea8c70da2..5a45a8ddb487a37dd9003c35b3e0f2cb901b42b0 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_main_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_substitutiongroup_main_e.ttcn
@@ -47,13 +47,6 @@ import from XSD all;
 import from www_example_org_substitutiongroup_ref all;
 
 
-type Subsgroup_group Refgroup
-with {
-  variant "name as uncapitalized";
-  variant "element";
-};
-
-
 type record ComplexGroup
 {
 	Subsgroup_group subsgroup
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_type_conversion_follow_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_type_conversion_follow_e.ttcn
index e7b9c63bba20e983f36a3f6c8233b2833d03883d..033a49dd1db125d3a2cb8339688c2465136a0d0f 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_type_conversion_follow_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_type_conversion_follow_e.ttcn
@@ -44,11 +44,23 @@ module www_example_org_type_conversion_follow {
 import from XSD all;
 
 
+type XSD.String E46
+with {
+  variant "name as uncapitalized";
+};
+
+
+type XSD.Integer E46_1
+with {
+  variant "name as 'e46_'";
+};
+
+
 type record E45
 {
 	XSD.String birthDateAttrGroup optional,
-	E45_1 birthPlaceAttrGroup optional,
-	E45_1 sd optional,
+	E46_1 birthPlaceAttrGroup optional,
+	E46_1 sd optional,
 	E45_1 foo,
 	XSD.String bar
 }
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_xsds/XmlTest_complex_import_AB.xsd b/regression_test/XML/XmlWorkflow/XmlTest_xsds/XmlTest_complex_import_AB.xsd
index 7c88324b7b6ae371d389c053f0df48369bffce5c..25148fab5a4d3ea1e72df3877dfa0da1da89edec 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_xsds/XmlTest_complex_import_AB.xsd
+++ b/regression_test/XML/XmlWorkflow/XmlTest_xsds/XmlTest_complex_import_AB.xsd
@@ -8,6 +8,7 @@
  Contributors:
   Balasko, Jeno
   Raduly, Csaba
+  Szabo, Bence Janos
 -->
 <schema xmlns="http://www.w3.org/2001/XMLSchema"
             xmlns:A="www.XmlTest.org/complex_import_A"
@@ -34,8 +35,8 @@
   <element name="purchaseReportImport">
     <complexType>
       <sequence>
-        <element name="myTypeA" type="A:MyType"/>
-        <element name="myTypeB" type="B:MyType"/>
+        <element ref="A:MyType"/>
+        <element ref="B:MyType"/>
       </sequence>
     </complexType>
   </element>
diff --git a/regression_test/XML/XmlWorkflow/src/xmlTest.prj b/regression_test/XML/XmlWorkflow/src/xmlTest.prj
index 5d1dcddc29b5511851ea823e00c47a89facda922..a5993898f577835538a8b1f6431fd995d71cdf4b 100644
--- a/regression_test/XML/XmlWorkflow/src/xmlTest.prj
+++ b/regression_test/XML/XmlWorkflow/src/xmlTest.prj
@@ -177,6 +177,7 @@
         <File path="../xsd/defaultforempty_mod2.xsd" />
         <File path="../xsd/defaultforempty_same_ns1.xsd" />
         <File path="../xsd/defaultforempty_same_ns2.xsd" />
+        <File path="../xsd/correct_ref_and_type.xsd" />
             </File_Group>
             <File_Group name="XmlTest_xsds" >
                 <File path="../XmlTest_xsds/XmlTest_boolean.xsd" />
@@ -426,6 +427,7 @@
             <File path="../XmlTest_expectedTtcns/www_example_org_defaultforempty_mod1_e.ttcn" />
             <File path="../XmlTest_expectedTtcns/www_example_org_defaultforempty_mod2_e.ttcn" />
             <File path="../XmlTest_expectedTtcns/www_example_org_defaultforempty_same_ns_e.ttcn" />
+            <File path="../XmlTest_expectedTtcns/http_www_example_org_correct_ref_and_type_e.ttcn" />
             </File_Group>
             <File_Group name="XmlTest_src" >
                 <File path="xmlTest_Shell.ttcn" />
diff --git a/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn b/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn
index 9215fe7f1bf50e14812b9385cca63c5554753899..446509d8b7afab4f3f6387861be9a3cd46c69c79 100644
--- a/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn
+++ b/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn
@@ -2482,6 +2482,19 @@ group Elements{
   }//tc_
 
 
+  testcase tc_correct_ref_and_type() runs on xmlTest_CT {
+
+    f_shellCommandWithVerdict(xsd2ttcn_command & " correct_ref_and_type.xsd","",c_shell_successWithoutWarningAndError)
+
+    if(getverdict==pass) {
+      f_compareFiles(
+        "http_www_example_org_correct_ref_and_type_e.ttcn",
+        "http_www_example_org_correct_ref_and_type.ttcn", c_numOfDiff);
+    }
+
+  }//tc_
+
+
 
   //========================================================
   // tc_element_nameInheritance_conv
@@ -2845,6 +2858,7 @@ control {
   execute(tc_simpletype_aliases());
   execute(tc_complextype_aliases());
 
+  execute(tc_correct_ref_and_type());
 
 
   execute(tc_element_nameInheritance_conv());
@@ -2862,6 +2876,7 @@ control {
   execute(tc_element_nillable_Isp_nilTrue_encDec());
   execute(tc_element_nillable_RemarkNillable_nilFalse_encDec());
   execute(tc_element_nillable_RemarkNillable_nilTrue_encDec());
+
 }
 
 } with {
diff --git a/regression_test/XML/XmlWorkflow/xsd/all.xsd b/regression_test/XML/XmlWorkflow/xsd/all.xsd
index 093c23dcb969b4e669d09144de3585d3658b5939..2250e42ac9966911de3ee978cd3dcf0f8f197d2d 100644
--- a/regression_test/XML/XmlWorkflow/xsd/all.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/all.xsd
@@ -26,13 +26,13 @@ targetNamespace="www.example.org/all">
 
 <xsd:annotation><xsd:documentation xml:lang="EN">All, mandatory</xsd:documentation></xsd:annotation>
 
-<xsd:complexType name="e29a"> 
+<xsd:group name="e29a"> 
 	<xsd:all>
 		<xsd:element name="foo" type="integer"/>
 		<xsd:element name="bar" type="float"/>
 		<xsd:element name="ding" type="string"/>
 	</xsd:all>
-</xsd:complexType>
+</xsd:group>
 
 <xsd:complexType name="e29aAndAttributes"> 
 	<xsd:all>
diff --git a/regression_test/XML/XmlWorkflow/xsd/anyattrib_single.xsd b/regression_test/XML/XmlWorkflow/xsd/anyattrib_single.xsd
index 3c70c4bb9ae3050642f539c2447aa4406d7bf770..f6571cdee2229addf172b144a18c7af5b5737845 100644
--- a/regression_test/XML/XmlWorkflow/xsd/anyattrib_single.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/anyattrib_single.xsd
@@ -21,16 +21,16 @@
 	<xsd:anyAttribute namespace="http://www.w3.org/1999/xhtml ##targetNamespace"/> 
 </xsd:complexType>
 
-<xsd:element name="e45c">
-	<xsd:complexType>
-		<xsd:anyAttribute namespace="##local http://www.example.org/attribute"/>
-	</xsd:complexType>
-</xsd:element>
+<xsd:element name="e45c" type="this:e45c_type"/>
+
+<xsd:complexType name="e45c_type">
+	<xsd:anyAttribute namespace="##local http://www.example.org/attribute"/>
+</xsd:complexType>
 
 <xsd:element name="e45d">
 	<xsd:complexType>
 		<xsd:complexContent>
-			<xsd:extension base="this:e45c">
+			<xsd:extension base="this:e45c_type">
 				<xsd:anyAttribute namespace="##targetNamespace"/>
 			</xsd:extension>
 		</xsd:complexContent>
diff --git a/regression_test/XML/XmlWorkflow/xsd/attrib_restriction_extension.xsd b/regression_test/XML/XmlWorkflow/xsd/attrib_restriction_extension.xsd
index c31d37797b20f5280ff63ec6f300e3a3006a6992..66df225e5c3f7576ab4c2fb529b7ac14f94c669d 100644
--- a/regression_test/XML/XmlWorkflow/xsd/attrib_restriction_extension.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/attrib_restriction_extension.xsd
@@ -20,7 +20,6 @@ xmlns:nss="www.example.org/attr/ext/rest"
 			<xsd:sequence>
 			</xsd:sequence>
 			<xsd:attribute name="gender" type="xsd:integer"/>
-			<xsd:attribute name="genderAttrBase" type="xsd:integer"/>
 		</xsd:extension>
 	</xsd:complexContent>
 </xsd:complexType>
@@ -42,7 +41,6 @@ xmlns:nss="www.example.org/attr/ext/rest"
 				<xsd:element name="ageElemExt" type="xsd:integer"/>
 			</xsd:sequence>
 			<xsd:attribute name="genderAttrBase" type="xsd:integer" use="prohibited"/>
-			<xsd:attribute name="boo" type="xsd:integer"/>
 		</xsd:restriction>
 	</xsd:complexContent>
 </xsd:complexType>
@@ -53,7 +51,7 @@ xmlns:nss="www.example.org/attr/ext/rest"
 			<xsd:sequence>
 				<xsd:element name="ageElemExt" type="xsd:integer"/>
 			</xsd:sequence>
-			<xsd:attribute name="genderAttrBase" type="xsd:integer" use="required"/>
+			<xsd:attribute name="genderAttrBase" type="xsd:integer" use="prohibited"/>
 		</xsd:restriction>
 	</xsd:complexContent>
 </xsd:complexType>
@@ -78,56 +76,52 @@ xmlns:nss="www.example.org/attr/ext/rest"
 				<xsd:element ref="nss:comment" minOccurs="1"/>
 			</xsd:sequence>
 			<xsd:attribute name="shipDate" type="xsd:date" use="required" />
-			<xsd:attribute name="boo" type="xsd:date"/>
 			<xsd:attribute name="orderDate" type="xsd:date" use="prohibited" />
 		</xsd:restriction>
 	</xsd:complexContent>
 </xsd:complexType> 
 
-<xsd:element name="e23">
-	<xsd:complexType>
-		<xsd:simpleContent>
-			<xsd:extension base="string">
-				<xsd:attribute name="foo" type="xsd:float"/>
-				<xsd:attribute name="bar" type="xsd:integer"/>
-				<xsd:attribute name="base" type="xsd:integer"/>
-			</xsd:extension>
-		</xsd:simpleContent>
-	</xsd:complexType>
-</xsd:element> 
+<xsd:element name="e23" type="nss:e23_type"/>
 
+<xsd:complexType name="e23_type">
+	<xsd:simpleContent>
+		<xsd:extension base="string">
+			<xsd:attribute name="foo" type="xsd:float"/>
+			<xsd:attribute name="bar" type="xsd:integer"/>
+			<xsd:attribute name="base" type="xsd:integer"/>
+		</xsd:extension>
+	</xsd:simpleContent>
+</xsd:complexType>
 
-<xsd:element name="e24">
-	<xsd:complexType>
-		<xsd:simpleContent>
-			<xsd:extension base="nss:e23">
-				<xsd:attribute name="foo" type="xsd:float"/>
-				<xsd:attribute name="goo" type="xsd:integer"/>
-				<xsd:attribute name="base" type="xsd:integer" use="required"/>
-			</xsd:extension>
-		</xsd:simpleContent>
-	</xsd:complexType>
-</xsd:element> 
 
+<xsd:element name="e24" type="nss:e24_type"/>
 
-<xsd:element name="e25">
-	<xsd:complexType>
-		<xsd:simpleContent>
-			<xsd:restriction base="nss:e24">
-				<xsd:length value="4"/> 
-				<xsd:attribute name="foo" type="xsd:float" use="prohibited"/>
-				<xsd:attribute name="goo" type="xsd:integer" use="required"/>
-				<xsd:attribute name="boo" type="xsd:integer"/>
-				<xsd:attribute name="base" type="xsd:integer" use="prohibited"/>
-			</xsd:restriction>
-		</xsd:simpleContent>
-	</xsd:complexType>
-</xsd:element> 
+<xsd:complexType name="e24_type">
+	<xsd:simpleContent>
+		<xsd:extension base="nss:e23_type">
+			<xsd:attribute name="goo" type="xsd:integer"/>
+		</xsd:extension>
+	</xsd:simpleContent>
+</xsd:complexType>
+
+
+<xsd:element name="e25" type="nss:e25_type"/>
+
+<xsd:complexType name="e25_type">
+	<xsd:simpleContent>
+		<xsd:restriction base="nss:e24_type">
+			<xsd:length value="4"/> 
+			<xsd:attribute name="foo" type="xsd:float" use="prohibited"/>
+			<xsd:attribute name="goo" type="xsd:integer" use="required"/>
+			<xsd:attribute name="base" type="xsd:integer" use="prohibited"/>
+		</xsd:restriction>
+	</xsd:simpleContent>
+</xsd:complexType>
 
 <xsd:element name="e26">
 	<xsd:complexType>
 		<xsd:simpleContent>
-			<xsd:extension base="nss:e25">
+			<xsd:extension base="nss:e25_type">
 				<xsd:attribute name="foo" type="xsd:float" use="required"/>
 			</xsd:extension>
 		</xsd:simpleContent>
diff --git a/regression_test/XML/XmlWorkflow/xsd/correct_ref_and_type.xsd b/regression_test/XML/XmlWorkflow/xsd/correct_ref_and_type.xsd
new file mode 100644
index 0000000000000000000000000000000000000000..5f875da685731819dc00836e44dc8e0952e3d5e5
--- /dev/null
+++ b/regression_test/XML/XmlWorkflow/xsd/correct_ref_and_type.xsd
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    targetNamespace="http://www.example.org/correct/ref/and/type"
+    xmlns:this="http://www.example.org/correct/ref/and/type">
+
+<xsd:group name="A">
+  <xsd:sequence>
+    <xsd:element name="aGroup"/>
+  </xsd:sequence>
+</xsd:group>
+
+<xsd:group name="B">
+  <xsd:sequence>
+    <xsd:element name="bGroup"/>
+    <xsd:group ref="this:A"/>
+  </xsd:sequence>
+</xsd:group>
+
+<xsd:complexType name="B">
+  <xsd:sequence>
+    <xsd:element name="baseElem" type="xsd:string"/>
+  </xsd:sequence>
+  <xsd:attribute name="baseAttr" type="this:A"/>
+</xsd:complexType>
+
+<xsd:attribute name="A" type="xsd:integer"/>
+
+<xsd:attribute name="B" type="xsd:integer"/>
+
+<xsd:attribute name="C" type="xsd:integer"/>
+
+<xsd:attributeGroup name="A">
+  <xsd:attribute name="Attr" type="xsd:integer"/>
+  <xsd:attribute ref="this:B"/>
+</xsd:attributeGroup>
+
+<xsd:element name="A" type="xsd:integer"/>
+
+<xsd:simpleType name="A">
+  <xsd:restriction base="xsd:string">
+    <xsd:enumeration value="SimpleType"/>
+    <xsd:enumeration value="SimpleType1"/>
+  </xsd:restriction>
+</xsd:simpleType>
+
+<xsd:simpleType name="C">
+  <xsd:union>
+    <xsd:simpleType>
+      <xsd:restriction base="xsd:integer"/>
+    </xsd:simpleType>
+    <xsd:simpleType>
+      <xsd:restriction base="xsd:string"/>
+    </xsd:simpleType>
+  </xsd:union>
+</xsd:simpleType> 
+
+
+<xsd:element name="Element">
+  <xsd:complexType>
+  <xsd:sequence>
+    <xsd:element ref="this:A"/>
+    <xsd:element name="SimpleTypeRef" type="this:A"/>
+    <xsd:element name="ComplexTypeRef" type="this:B"/>
+    <xsd:group ref="this:B"/>
+  </xsd:sequence>
+  <xsd:attribute ref="this:A"/>
+  <xsd:attribute name="SimpleTypeAttr" type="this:A"/>
+  <xsd:attribute name="SimpleTypeAttr2" type="this:C"/>
+  <xsd:attributeGroup ref="this:A"/>
+</xsd:complexType>
+</xsd:element>
+
+<xsd:simpleType name="AExtension">
+  <xsd:restriction base="this:A">
+    <xsd:enumeration value="SimpleType"/>
+  </xsd:restriction>
+</xsd:simpleType>
+
+<xsd:element name="AType" type="this:A"/>
+
+<xsd:attribute name="AAttr" type="this:A"/>
+
+<xsd:element name="BType" type="this:B"/>
+
+<xsd:attribute name="BAttr" type="this:B"/>
+
+<xsd:complexType name="SimpleTypExtension">
+  <xsd:simpleContent>
+    <xsd:extension base="this:A">
+      <xsd:attribute name="attr" type="xsd:integer"/>
+    </xsd:extension>
+  </xsd:simpleContent>
+</xsd:complexType>
+
+<xsd:complexType name="SimpleTypeRestriction">
+  <xsd:simpleContent>
+    <xsd:restriction base="this:A">
+      <xsd:enumeration value="SimpleType"/>
+    </xsd:restriction>
+  </xsd:simpleContent>
+</xsd:complexType>
+
+<xsd:complexType name="ComplexTypeExtension">
+  <xsd:complexContent>
+    <xsd:extension base="this:B">
+      <xsd:sequence>
+        <xsd:element name="Extelem" type="xsd:integer"/>
+      </xsd:sequence>
+      <xsd:attribute name="Extattr" type="this:A"/>
+    </xsd:extension>
+  </xsd:complexContent>
+</xsd:complexType>
+
+<xsd:complexType name="ComplexTypeRestriction">
+  <xsd:complexContent>
+    <xsd:restriction base="this:B">
+      <xsd:sequence>
+        <xsd:element name="baseElem" type="xsd:string"/>
+      </xsd:sequence>
+      <xsd:attribute name="baseAttr" type="this:A" use="prohibited"/>
+    </xsd:restriction>
+  </xsd:complexContent>
+</xsd:complexType>
+
+<xsd:complexType name="ComplexTypeGroup">
+  <xsd:sequence>
+    <xsd:group ref="this:B" maxOccurs="4"/>
+  </xsd:sequence>
+</xsd:complexType>
+
+
+</xsd:schema>
\ No newline at end of file
diff --git a/regression_test/XML/XmlWorkflow/xsd/dont_generate_element_substitution.xsd b/regression_test/XML/XmlWorkflow/xsd/dont_generate_element_substitution.xsd
index 8c76a1f864065753ea9c73a597f35707dbf93bea..9fddd3466bd57bedc4fe7a41e096746414093bbf 100644
--- a/regression_test/XML/XmlWorkflow/xsd/dont_generate_element_substitution.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/dont_generate_element_substitution.xsd
@@ -7,21 +7,21 @@
 
 <xsd:element name="head" type="string" />
 
-<xsd:element name="complexEnum">
-	<xsd:complexType>
-		<xsd:simpleContent>
-			<xsd:extension base="xsd:string">
-				<xsd:attribute name="foo" type="xsd:float"/>
-				<xsd:attribute name="bar" type="xsd:integer"/>
-			</xsd:extension>
-		</xsd:simpleContent>
-	</xsd:complexType>
-</xsd:element>
+<xsd:element name="complexEnum" type="this:complexEnum_type"/>
+
+<xsd:complexType name="complexEnum_type">
+	<xsd:simpleContent>
+		<xsd:extension base="xsd:string">
+			<xsd:attribute name="foo" type="xsd:float"/>
+			<xsd:attribute name="bar" type="xsd:integer"/>
+		</xsd:extension>
+	</xsd:simpleContent>
+</xsd:complexType>
 
 <xsd:element name="member2"  substitutionGroup="this:head">
 	<xsd:complexType >
 		<xsd:complexContent>
-			<xsd:extension base="this:complexEnum">
+			<xsd:extension base="this:complexEnum_type">
 				<xsd:sequence>
 				</xsd:sequence>
 				<xsd:attribute name="unitOfAge" type="xsd:string"/>
diff --git a/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction.xsd b/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction.xsd
index cbde162ce3d3cc9bc0bad710ddb81b6e7c156797..5b5d0bdf1cd8538844bd751e4fdc37fe7f6c6f4b 100644
--- a/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction.xsd
@@ -4,24 +4,24 @@
  targetNamespace="www.example.org/enumeration/restriction"
  xmlns:this="www.example.org/enumeration/restriction">
 
-<xs:element name="e21unnamed">
-	<xs:simpleType>
-		<union>
- 			<xs:simpleType>
-				<restriction base="xs:integer"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:float"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<xs:restriction base="xs:string"/>
-			</xs:simpleType>
-		</union>
-	</xs:simpleType>
-</xs:element>
+<xs:element name="e21unnamed" type="this:e21unnamed_type"/>
+
+<xs:simpleType name="e21unnamed_type">
+	<union>
+		<xs:simpleType>
+			<restriction base="xs:integer"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:float"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<xs:restriction base="xs:string"/>
+		</xs:simpleType>
+	</union>
+</xs:simpleType>
 
 <xs:simpleType name="e22"> 
-	<xs:restriction base="this:e21unnamed">
+	<xs:restriction base="this:e21unnamed_type">
 		<xs:enumeration value="20.4"/>
 		<xs:enumeration value="50"/>
 		<xs:enumeration value="small"/>
@@ -29,69 +29,69 @@
 </xs:simpleType>
 
 
-<xs:element name="String_int">
-	<xs:simpleType>
-		<union>
-			<xs:simpleType>
-				<xs:restriction base="xs:string"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:integer"/>
-			</xs:simpleType>
-		</union>
-	</xs:simpleType>
-</xs:element>
+<xs:element name="String_int" type="this:String_int_type"/>
+
+<xs:simpleType name="String_int_type">
+	<union>
+		<xs:simpleType>
+			<xs:restriction base="xs:string"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:integer"/>
+		</xs:simpleType>
+	</union>
+</xs:simpleType>
 
 <xs:simpleType name="Everything_is_string"> 
-	<xs:restriction base="this:String_int">
+	<xs:restriction base="this:String_int_type">
 		<xs:enumeration value="20.4"/>
 		<xs:enumeration value="50"/>
 		<xs:enumeration value="small"/>
 	</xs:restriction>
 </xs:simpleType>
 
-<xs:element name="Mixed_Types">
-	<xs:simpleType>
-		<union>
-			<xs:simpleType>
-				<restriction base="xs:gDay"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<xs:restriction base="xs:gYear"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:gMonth"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:float"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:date"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:time"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:dateTime"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:gMonthDay"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:duration"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<restriction base="xs:gYearMonth"/>
-			</xs:simpleType>
-			<xs:simpleType>
-				<xs:restriction base="xs:string"/>
-			</xs:simpleType>	
-		</union>
-	</xs:simpleType>
-</xs:element>
+<xs:element name="Mixed_Types" type="this:Mixed_Types_type"/>
+	
+<xs:simpleType name="Mixed_Types_type">
+	<union>
+		<xs:simpleType>
+			<restriction base="xs:gDay"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<xs:restriction base="xs:gYear"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:gMonth"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:float"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:date"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:time"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:dateTime"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:gMonthDay"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:duration"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<restriction base="xs:gYearMonth"/>
+		</xs:simpleType>
+		<xs:simpleType>
+			<xs:restriction base="xs:string"/>
+		</xs:simpleType>	
+	</union>
+</xs:simpleType>
 
 <xs:simpleType name="Mixed_Enum"> 
-	<xs:restriction base="this:Mixed_Types">
+	<xs:restriction base="this:Mixed_Types_type">
 		<xs:enumeration value="somestring"/>
 		<xs:enumeration value="2014-01-01"/>
 		<xs:enumeration value="20.4"/>
@@ -108,20 +108,19 @@
 	</xs:restriction>
 </xs:simpleType>
 
-<xs:element name="Only_int">
-	<xs:simpleType>
-		<union>
-			<xs:simpleType>
-				<restriction base="xs:integer"/>
-			</xs:simpleType>
-		</union>
-	</xs:simpleType>
-</xs:element>
+<xs:element name="Only_int" type="this:Only_int_type"/>
+
+<xs:simpleType name="Only_int_type">
+	<union>
+		<xs:simpleType>
+			<restriction base="xs:integer"/>
+		</xs:simpleType>
+	</union>
+</xs:simpleType>
 
 <xs:simpleType name="Ints"> 
-	<xs:restriction base="this:Only_int">
+	<xs:restriction base="this:Only_int_type">
 		<xs:enumeration value="14"/>
-		<xs:enumeration value="somestring"/>
 	</xs:restriction>
 </xs:simpleType>
 
diff --git a/regression_test/XML/XmlWorkflow/xsd/generate_element_substitution.xsd b/regression_test/XML/XmlWorkflow/xsd/generate_element_substitution.xsd
index 435600ecf8fe395e9219454cdd7f7f1ef7ed693b..8ba65659d54497280781a8b4cb397d75a1a20a5f 100644
--- a/regression_test/XML/XmlWorkflow/xsd/generate_element_substitution.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/generate_element_substitution.xsd
@@ -7,21 +7,21 @@
 
 <xsd:element name="head" type="string" />
 
-<xsd:element name="complexEnum">
-	<xsd:complexType>
-		<xsd:simpleContent>
-			<xsd:extension base="xsd:string">
-				<xsd:attribute name="foo" type="xsd:float"/>
-				<xsd:attribute name="bar" type="xsd:integer"/>
-			</xsd:extension>
-		</xsd:simpleContent>
-	</xsd:complexType>
-</xsd:element>
+<xsd:element name="complexEnum" type="this:complexEnum_type"/>
+
+<xsd:complexType name="complexEnum_type">
+	<xsd:simpleContent>
+		<xsd:extension base="xsd:string">
+			<xsd:attribute name="foo" type="xsd:float"/>
+			<xsd:attribute name="bar" type="xsd:integer"/>
+		</xsd:extension>
+	</xsd:simpleContent>
+</xsd:complexType>
 
 <xsd:element name="member2"  substitutionGroup="this:head">
 	<xsd:complexType >
 		<xsd:complexContent>
-			<xsd:extension base="this:complexEnum">
+			<xsd:extension base="this:complexEnum_type">
 				<xsd:sequence>
 				</xsd:sequence>
 				<xsd:attribute name="unitOfAge" type="xsd:string"/>
diff --git a/regression_test/XML/XmlWorkflow/xsd/imported2.xsd b/regression_test/XML/XmlWorkflow/xsd/imported2.xsd
index 3755b5f83e6b65fb9be9d0aae6509337c54170fc..feedcf65c79a9ff58441ad44f4f3fd359d2f5447 100644
--- a/regression_test/XML/XmlWorkflow/xsd/imported2.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/imported2.xsd
@@ -1,21 +1,24 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
- targetNamespace="www.example.org/imported2">
+ targetNamespace="www.example.org/imported2"
+ xmlns:this="www.example.org/imported2">
 
 <xsd:simpleType name="foobar">
 	<xsd:restriction base="xsd:integer"/>
 </xsd:simpleType>
 
+<xsd:element name="foobarElem" type="this:foobar"/>
+
 <xsd:simpleType name="ding">
 	<xsd:restriction base="xsd:integer"/>
 </xsd:simpleType>
 
-<xsd:element name="bar">
-	<xsd:complexType>
-		<xsd:sequence>
-			<xsd:element name="something" type="xsd:string" minOccurs="0"/>
-		</xsd:sequence>
-	</xsd:complexType>
-</xsd:element>
+<xsd:element name="bar" type="this:bar_type"/>
+
+<xsd:complexType name="bar_type">
+	<xsd:sequence>
+		<xsd:element name="something" type="xsd:string" minOccurs="0"/>
+	</xsd:sequence>
+</xsd:complexType>
 
 </xsd:schema> 
diff --git a/regression_test/XML/XmlWorkflow/xsd/name_conversion_extension_attrib.xsd b/regression_test/XML/XmlWorkflow/xsd/name_conversion_extension_attrib.xsd
index bf75f849c41e7c176fbad05cc11c1fcb2fed5338..65050f05026f530aeb6b722910323aa1009a08ce 100644
--- a/regression_test/XML/XmlWorkflow/xsd/name_conversion_extension_attrib.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/name_conversion_extension_attrib.xsd
@@ -7,14 +7,16 @@
 	 elementFormDefault="qualified"
 	 attributeFormDefault="unqualified">
 	 
-<xs:element name="Ol-name-type">
-	<xs:complexType>
-		<xs:sequence>
-			<xs:element name="allow-true-action" type="xs:integer">
-			</xs:element>
-		</xs:sequence>
-	</xs:complexType>
-</xs:element>
+<xs:element name="Ol-name-type" type="Ol-name-type_type"/>
+
+<xs:complexType name="Ol-name-type_type">
+	<xs:sequence>
+		<xs:element name="allow-true-action" type="xs:integer">
+		</xs:element>
+	</xs:sequence>
+</xs:complexType>
+
+<xs:attribute name="Attr" type="xs:string"/>
 
 <xs:element name="Ol-actions-type">
 	<xs:complexType>
@@ -24,8 +26,8 @@
 			<xs:element name="play-segmented-announcement" nillable="true">
 					<xs:complexType>
 						<xs:complexContent>
-							<xs:extension base="ns:Ol-name-type">
-								<xs:attribute name="announcement-name" type="ns:Ol-name-type" use="required"/>
+							<xs:extension base="ns:Ol-name-type_type">
+								<xs:attribute ref="ns:Attr" use="required"/>
 							</xs:extension>
 						</xs:complexContent>
 					</xs:complexType>
@@ -42,11 +44,11 @@
 			<xs:element name="play-segmented-announcement" nillable="true">
 					<xs:complexType>
 						<xs:complexContent>
-							<xs:extension base="ns:Ol-name-type">
+							<xs:extension base="ns:Ol-name-type_type">
 								<xs:sequence>
 									<xs:element name="elem" type="xs:string"/>
 								</xs:sequence>
-								<xs:attribute name="announcement-name" type="ns:Ol-name-type" use="required"/>
+								<xs:attribute ref="ns:Attr" use="required"/>
 							</xs:extension>
 						</xs:complexContent>
 					</xs:complexType>
diff --git a/regression_test/XML/XmlWorkflow/xsd/namespaceas.xsd b/regression_test/XML/XmlWorkflow/xsd/namespaceas.xsd
index a6d9e9103bdcc12120a9409b6a9caef9993fe2be..d2a4a118329dc4b40132b0026e595b49e01e79e1 100644
--- a/regression_test/XML/XmlWorkflow/xsd/namespaceas.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/namespaceas.xsd
@@ -14,7 +14,7 @@
 	<xsd:complexType>
 		<xsd:sequence>
 			<xsd:element name="something" type="other:foobar" minOccurs="0" />
-			<xsd:element ref="other:foobar"/>
+			<xsd:element ref="other:foobarElem"/>
 		</xsd:sequence>
 	</xsd:complexType>
 </xsd:element>
@@ -33,22 +33,22 @@
 		</xsd:element>
 		<xsd:element name="something2">
 			<xsd:complexType>
-				<xsd:simpleContent>
-					<xsd:extension base="other:bar"/>
-				</xsd:simpleContent>
+				<xsd:complexContent>
+					<xsd:extension base="other:bar_type"/>
+				</xsd:complexContent>
 			</xsd:complexType>
 		</xsd:element>
 		<xsd:element name="something3">
 			<xsd:complexType>
 				<xsd:complexContent>
-					<xsd:extension base="other:bar"/>
+					<xsd:extension base="other:bar_type"/>
 				</xsd:complexContent>
 			</xsd:complexType>
 		</xsd:element>
 		<xsd:element name="something4">
 			<xsd:complexType>
 					<xsd:complexContent>
-						<xsd:restriction base="other:bar">
+						<xsd:restriction base="other:bar_type">
 							<xsd:sequence>
 								<xsd:element name="something" type="string" minOccurs="1"/>
 							</xsd:sequence>
diff --git a/regression_test/XML/XmlWorkflow/xsd/only_element_substitution.xsd b/regression_test/XML/XmlWorkflow/xsd/only_element_substitution.xsd
index dd6f1953bb387e353bc949c17d62bfc0b0838110..9df51c9a07c2a995aa0d0bbca4bc20eba68e5702 100644
--- a/regression_test/XML/XmlWorkflow/xsd/only_element_substitution.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/only_element_substitution.xsd
@@ -13,7 +13,7 @@
 
 <!-- Production implementation -->
 
-<xsd:element name="productionRequest" substitutionGroup="requestAbstractType" >
+<xsd:element name="productionRequest" substitutionGroup="requestAbstractType1" >
 	<xsd:complexType>
 		<xsd:complexContent>
 			<xsd:extension base="requestAbstractType">
@@ -26,7 +26,7 @@
 </xsd:element>
 
 <!-- Production implementation -->
-<xsd:element name="programmingRequest"  substitutionGroup="requestAbstractType" >
+<xsd:element name="programmingRequest"  substitutionGroup="requestAbstractType1" >
 	<xsd:complexType>
 		<xsd:complexContent>
 			<xsd:extension base="requestAbstractType">
@@ -38,5 +38,13 @@
 	</xsd:complexType>
 </xsd:element>
 
+<xsd:element name="ize">
+	<xsd:complexType>
+		<xsd:sequence>
+			<xsd:element ref="requestAbstractType1" minOccurs="0" maxOccurs="unbounded"/>
+		</xsd:sequence>
+	</xsd:complexType>
+</xsd:element>
+
 </xsd:schema>
 
diff --git a/regression_test/XML/XmlWorkflow/xsd/simpletype_ref.xsd b/regression_test/XML/XmlWorkflow/xsd/simpletype_ref.xsd
index ff05d58cb62d953d4c4a222acf1011e1e7e7fc00..1c2d030db3c3280d75174a80ae23b063d02677ce 100644
--- a/regression_test/XML/XmlWorkflow/xsd/simpletype_ref.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/simpletype_ref.xsd
@@ -4,32 +4,34 @@
  xmlns:this="www.example.org/simpletype/ref"
  targetNamespace="www.example.org/simpletype/ref">
 
-<xsd:element name="SomeType">
-	<xsd:complexType>
-		<xsd:complexContent>
-			<xsd:restriction base="this:Type">
-				<xsd:sequence>
-					<xsd:element name="something" type="xsd:string"/>
-				</xsd:sequence>
-			</xsd:restriction>
-		</xsd:complexContent>
-	</xsd:complexType>
-</xsd:element>
+<xsd:element name="SomeType" type="this:SomeType_type"/>
 
-<xsd:element name="Type">
-	<xsd:complexType>
-		<xsd:sequence>
-			<xsd:element name="something" type="xsd:string" minOccurs="0" />
-		</xsd:sequence>
-	</xsd:complexType>
-</xsd:element>
+<xsd:complexType name="SomeType_type">
+	<xsd:complexContent>
+		<xsd:restriction base="this:Type_type">
+			<xsd:sequence>
+				<xsd:element name="something" type="xsd:string"/>
+			</xsd:sequence>
+		</xsd:restriction>
+	</xsd:complexContent>
+</xsd:complexType>
+
+<xsd:element name="Type" type="this:Type_type"/>
+
+<xsd:complexType name="Type_type">
+	<xsd:sequence>
+		<xsd:element name="something" type="xsd:string" minOccurs="0" />
+	</xsd:sequence>
+</xsd:complexType>
 
 <xsd:complexType name="OtherType">
 	<xsd:sequence>
 		<xsd:element name="billingAccountNumber">
-			<xsd:simpleType>
-				<xsd:restriction base="this:SomeType"/>
-			</xsd:simpleType>
+			<xsd:complexType>
+				<xsd:complexContent>
+					<xsd:extension base="this:SomeType_type"/>
+				</xsd:complexContent>
+			</xsd:complexType>
 		</xsd:element>
 		<xsd:element name="installmentPlanId">
 			<xsd:simpleType>
diff --git a/regression_test/XML/XmlWorkflow/xsd/substitutiongroup.xsd b/regression_test/XML/XmlWorkflow/xsd/substitutiongroup.xsd
index 475238d31743351df71b2d457b4079b426816973..f4d6c06483c744050817323508fd4b8536000ae8 100644
--- a/regression_test/XML/XmlWorkflow/xsd/substitutiongroup.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/substitutiongroup.xsd
@@ -4,6 +4,9 @@
  xmlns:subs="www.example.org/substitutiongroup"
  targetNamespace="www.example.org/substitutiongroup">
 
+<!-- TEST IF THE ELEMENT REFERENCE IS FOUND -->
+<xsd:attribute name="head" type="xsd:integer"/>
+
 <!-- THE HEAD ELEMENT -->
 <xsd:element name="head" type="xsd:string" />
 
diff --git a/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_complex_without_element.xsd b/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_complex_without_element.xsd
index 3e72e95a6e9cc2de5b3765ec7f60ae95c70bb43f..7fb70d86d5a7639d784354dab8a2e66b9195715f 100644
--- a/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_complex_without_element.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_complex_without_element.xsd
@@ -7,32 +7,37 @@
 
 <xsd:element name="Head_group" type="string" />
 
-<xsd:element name="member" type="string" substitutionGroup="this:head"/>
+<xsd:element name="member" type="this:head_type" substitutionGroup="this:head"/>
 
 <xsd:element name="stringEnum" substitutionGroup="this:head">
-	<xsd:simpleType>
-		<xsd:restriction base="xsd:string">
-			<xsd:enumeration value="something"/>
-			<xsd:enumeration value="else"/>
-		</xsd:restriction>
-	</xsd:simpleType> 
+	<xsd:complexType>
+		<xsd:complexContent>
+			<xsd:restriction base="this:head_type">
+				<xsd:sequence>
+					<xsd:element name="Something" type="string" />
+				</xsd:sequence>
+				<xsd:attribute name="headAttrib" type="xsd:string" use="required"/>
+			</xsd:restriction>
+		</xsd:complexContent>
+	</xsd:complexType> 
 </xsd:element>
 
-<xsd:element name="head"  abstract="true">
-	<xsd:complexType >
-		<xsd:sequence>
-			<xsd:element name="Something" type="string" />
-		</xsd:sequence>
-		<xsd:attribute name="headAttrib" type="xsd:string"/>
-	</xsd:complexType>
+<xsd:element name="head" type="this:head_type" abstract="true">
+	
 </xsd:element>
 
+<xsd:complexType name="head_type">
+	<xsd:sequence>
+		<xsd:element name="Something" type="string" />
+	</xsd:sequence>
+	<xsd:attribute name="headAttrib" type="xsd:string"/>
+</xsd:complexType>
 
 <xsd:element name="member2" type="this:e26seq" substitutionGroup="this:head" />
 
 <xsd:complexType name="e26seq">
 	<xsd:complexContent>
-		<xsd:extension base="this:head">
+		<xsd:extension base="this:head_type">
 			<xsd:sequence>
 				<xsd:element name="ageElemExt" type="xsd:integer"/>
 			</xsd:sequence>
diff --git a/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_main.xsd b/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_main.xsd
index f61318c7d6238cb9d11f6d0215a1f0f4c5d9f9d6..4b92a1adda5b9d7ae17dc3e4fddc5c4ab4ec3159 100644
--- a/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_main.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/substitutiongroup_main.xsd
@@ -6,8 +6,6 @@
 
 <xsd:element name="subsgroup" type="xsd:string" abstract="true" />
 
-<xsd:element name="refgroup" type="A:subsgroup" />
-
 <xsd:complexType name="complexGroup">
 	<xsd:sequence>
 		<xsd:element ref="A:subsgroup"/>
diff --git a/regression_test/XML/XmlWorkflow/xsd/type_conversion_follow.xsd b/regression_test/XML/XmlWorkflow/xsd/type_conversion_follow.xsd
index 6dfc93eeea8c039601d95842b98cfc56225413a7..16717c53cfe07c5e330a377ed76538e37db9b4f2 100644
--- a/regression_test/XML/XmlWorkflow/xsd/type_conversion_follow.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/type_conversion_follow.xsd
@@ -4,12 +4,22 @@
  targetNamespace="www.example.org/type/conversion/follow"
  xmlns:ns11="www.example.org/type/conversion/follow"> 
 
+<xsd:simpleType name="e46">
+	<xsd:restriction base="xsd:string">
+	</xsd:restriction>
+</xsd:simpleType>
+
+<xsd:simpleType name="e46_">
+	<xsd:restriction base="xsd:integer">
+	</xsd:restriction>
+</xsd:simpleType>
 
 <xsd:complexType name="e45"> 
 	<group ref="ns11:foobarGroup"/>
-		<attribute name="sd" type="ns11:e45_"/>
+	<attribute name="sd" type="ns11:e46_"/>
 	<attributeGroup ref="ns11:g25attr1"/>
 </xsd:complexType> 
+
 <xsd:complexType name="e45_"> 
 	<xsd:attribute name="attr" type="xsd:string"/> 
 </xsd:complexType> 
@@ -26,7 +36,7 @@
 </element>
 
 <xsd:attributeGroup name="g25attr1">
-	<xsd:attribute name="birthPlaceAttrGroup" type="ns11:e45_"/>
+	<xsd:attribute name="birthPlaceAttrGroup" type="ns11:e46_"/>
 	<xsd:attribute name="birthDateAttrGroup" type="xsd:string"/>
 </xsd:attributeGroup> 
 
diff --git a/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref1.xsd b/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref1.xsd
index d55221cf6aa75ebbb9b86dc6e82d1f40d2673227..3585db57de2416f092d470d2db4367414074461e 100644
--- a/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref1.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref1.xsd
@@ -15,13 +15,13 @@
 			<element ref="ns2:MyElement"/>
 			<element ref="ns2:MyElement2"/>
 		</sequence>
-		<attribute ref="ns2:MyElement"/>
-		<attribute ref="ns2:MyElement2"/>
+		<attribute ref="ns2:MyAttribute"/>
+		<attribute ref="ns2:MyAttribute2"/>
 	</complexType>
   </element>
 
-  <element name="MyElement" type="ns2:MyElement"/>
+  <element name="MyElement" type="ns2:MyType"/>
 
-  <element name="MyElement" type="ns2:MyElement2"/>
+  <element name="MyElement" type="ns2:MyType"/>
 
 </schema>
diff --git a/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref2.xsd b/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref2.xsd
index 4502f259e555eb32deecb1ea28a712e25f61c41c..757d65946dbffedd962295934ab65567f6c687bb 100644
--- a/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref2.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/www_example_org_pref2.xsd
@@ -5,6 +5,8 @@
 	xmlns:ns="www.example.org/pref2">
 	<element name="MyElement" type="ns:MyType" />
 	<element name="MyElement2" type="ns:MyType" />
+	<attribute name="MyAttribute" type="ns:MyType" />
+	<attribute name="MyAttribute2" type="ns:MyType" />
 	<complexType name="MyType">
 		<sequence>
 			<element name="myField" type="integer" />
diff --git a/xsdconvert/ComplexType.cc b/xsdconvert/ComplexType.cc
index 5ef2d6c31fe51792ee404c4736577a61e0680a59..f0b025d8f4b12e9ff8863515f5322bef0b4dd304 100644
--- a/xsdconvert/ComplexType.cc
+++ b/xsdconvert/ComplexType.cc
@@ -42,7 +42,6 @@ ComplexType::ComplexType(XMLParser * a_parser, TTCN3Module * a_module, Construct
 , lastType()
 , actualPath(empty_string)
 , actfield(this)
-, nameDep(NULL)
 , nillable_field(NULL)
 , basefield(NULL)
 , cmode(CT_undefined_mode)
@@ -72,7 +71,6 @@ ComplexType::ComplexType(ComplexType & other)
 , lastType(other.lastType)
 , actualPath(other.actualPath)
 , actfield(this)
-, nameDep(other.nameDep)
 , nillable_field(NULL)
 , basefield(NULL)
 , cmode(other.cmode)
@@ -122,7 +120,6 @@ ComplexType::ComplexType(ComplexType * other)
 , lastType()
 , actualPath(empty_string)
 , actfield(this)
-, nameDep(NULL)
 , nillable_field(NULL)
 , basefield(NULL)
 , cmode(CT_undefined_mode)
@@ -154,7 +151,6 @@ ComplexType::ComplexType(const SimpleType & other, CT_fromST c)
 , lastType()
 , actualPath(empty_string)
 , actfield(this)
-, nameDep(NULL)
 , nillable_field(NULL)
 , basefield(NULL)
 , cmode(CT_simpletype_mode)
@@ -170,7 +166,7 @@ ComplexType::ComplexType(const SimpleType & other, CT_fromST c)
     module->setActualXsdConstruct(c_complexType);
   }
   construct = c_complexType;
-
+  
   switch (c) {
     case fromTagUnion:
       type.upload(Mstring("union"), false);
@@ -197,6 +193,7 @@ ComplexType::ComplexType(const SimpleType & other, CT_fromST c)
       pattern.modified = false;
       length.modified = false;
       whitespace.modified = false;
+      new_construct = c_complexType;
       break;
     case fromTypeSubstitution:
       type.upload(Mstring("union"), false);
@@ -211,6 +208,7 @@ ComplexType::ComplexType(const SimpleType & other, CT_fromST c)
       pattern.modified = false;
       length.modified = false;
       whitespace.modified = false;
+      new_construct = c_complexType;
   }
 }
 
@@ -724,7 +722,7 @@ void ComplexType::referenceResolving() {
   }
   resolved = InProgress;
   for (List<ComplexType*>::iterator ct = complexfields.begin(); ct; ct = ct->Next) {
-    // Referenece resolving of ComplexTypes
+    // Reference resolving of ComplexTypes
     ct->Data->referenceResolving();
   }
   for (List<AttributeType*>::iterator attr = attribfields.begin(); attr; attr = attr->Next) {
@@ -751,20 +749,11 @@ void ComplexType::reference_resolving_funtion() {
     return;
   }
 
-  SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(this, want_BOTH);
-  if (st == NULL && basefield == NULL) {
-    printError(module->getSchemaname(), name.convertedValue,
-      "Reference for a non-defined type: " + getReference().repr());
-    TTCN3ModuleInventory::getInstance().incrNumErrors();
-    outside_reference.set_resolved(NULL);
-    return;
-  }
+  resolveAttributeGroup();
 
-  resolveAttributeGroup(st);
+  resolveGroup();
 
-  resolveGroup(st);
-
-  resolveElement(st);
+  resolveElement();
 
   resolveSimpleTypeExtension();
 
@@ -774,7 +763,7 @@ void ComplexType::reference_resolving_funtion() {
 
   resolveComplexTypeRestriction();
 
-  resolveUnion(st);
+  resolveUnion();
 
   addToTypeSubstitutions();
 
@@ -1702,7 +1691,8 @@ void ComplexType::addNameSpaceAsVariant(RootType * root, RootType * other) {
 
 void ComplexType::resolveAttribute(AttributeType* attr) {
   if (attr->getXsdtype() == n_attribute && !attr->getReference().empty()) {
-    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(attr, want_BOTH);
+    ConstructType type_construct = attr->isFromRef() ? c_attribute : c_simpleType;
+    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(attr, want_BOTH, type_construct);
     if (st != NULL) {
       attr->setBuiltInBase(st->getBuiltInBase());
       if (attr->isFromRef()) {
@@ -1711,6 +1701,7 @@ void ComplexType::resolveAttribute(AttributeType* attr) {
         attr->setNameOfField(st->getName().originalValueWoPrefix);
         attr->setOrigModule(st->getModule());
         st->addToNameDepList(attr);
+        attr->nameDep = st;
         if (attr->getConstantDefaultForEmpty() != NULL) {
           st->addToNameDepList((RootType*)attr->getConstantDefaultForEmpty());
         }
@@ -1720,6 +1711,7 @@ void ComplexType::resolveAttribute(AttributeType* attr) {
             || st->getXsdtype() == n_NOTSET) // It really is a simpleType
           {
             st->addToNameDepList(attr);
+            attr->nameDep = st;
             if (attr->getConstantDefaultForEmpty() != NULL) {
               st->addToNameDepList((RootType*)attr->getConstantDefaultForEmpty());
             }
@@ -1728,14 +1720,22 @@ void ComplexType::resolveAttribute(AttributeType* attr) {
       attr->getReference().set_resolved(st);
     } else {
       printError(module->getSchemaname(), name.convertedValue,
-        "Reference for a non-defined type: " + attr->getReference().repr());
+        "Reference for a non-defined attribute or simpleType type: " + attr->getReference().repr());
       TTCN3ModuleInventory::getInstance().incrNumErrors();
     }
   }
 }
 
-void ComplexType::resolveAttributeGroup(SimpleType * st) {
+void ComplexType::resolveAttributeGroup() {
   if (xsdtype == n_attributeGroup && !outside_reference.empty()) {
+    SimpleType* st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(this, want_BOTH, c_attributeGroup);
+    if (st == NULL && basefield == NULL) {
+      printError(module->getSchemaname(), name.convertedValue,
+        "Reference for a non-defined attributeGroup type: " + getReference().repr());
+      TTCN3ModuleInventory::getInstance().incrNumErrors();
+      outside_reference.set_resolved(NULL);
+      return;
+    }
     ComplexType * ct = (ComplexType*) st;
     if(ct->resolved == No){
       ct->referenceResolving();
@@ -1788,8 +1788,16 @@ void ComplexType::resolveAttributeGroup(SimpleType * st) {
   }
 }
 
-void ComplexType::resolveGroup(SimpleType *st) {
+void ComplexType::resolveGroup() {
   if (xsdtype == n_group && !outside_reference.empty()) {
+    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(this, want_BOTH, c_group);
+    if (st == NULL && basefield == NULL) {
+      printError(module->getSchemaname(), name.convertedValue,
+        "Reference for a non-defined group type: " + getReference().repr());
+      TTCN3ModuleInventory::getInstance().incrNumErrors();
+      outside_reference.set_resolved(NULL);
+      return;
+    }
     ComplexType * ct = (ComplexType*) st;
     outside_reference.set_resolved(ct);
     setInvisible();
@@ -1843,8 +1851,17 @@ void ComplexType::resolveGroup(SimpleType *st) {
   }
 }
 
-void ComplexType::resolveElement(SimpleType *st) {
+void ComplexType::resolveElement() {
   if (xsdtype == n_element && !outside_reference.empty()) {
+    ConstructType type_construct = fromRef ? c_element : c_simpleOrComplexType;
+    SimpleType* st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(this, want_BOTH, type_construct);
+    if (st == NULL && basefield == NULL) {
+      printError(module->getSchemaname(), name.convertedValue,
+        "Reference for a non-defined element or simpleType or complexType type: " + getReference().repr());
+      TTCN3ModuleInventory::getInstance().incrNumErrors();
+      outside_reference.set_resolved(NULL);
+      return;
+    }
     outside_reference.set_resolved(st);
     type.upload(st->getModule()->getTargetNamespaceConnector() + Mstring(":") + st->getName().convertedValue);
     if (name.originalValueWoPrefix.empty()) {
@@ -1881,7 +1898,8 @@ void ComplexType::resolveElement(SimpleType *st) {
 
 void ComplexType::resolveSimpleTypeExtension() {
   if (mode == extensionMode && cmode == CT_simpletype_mode && basefield != NULL) {
-    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(basefield, want_BOTH);
+    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(basefield, want_BOTH, c_simpleOrComplexType);
+    
     if (st != NULL) {
       if (st->getXsdtype() != n_NOTSET && ((ComplexType*) st)->basefield != NULL) { // if the xsdtype != simpletype
         ComplexType * ct = (ComplexType*) st;
@@ -1955,11 +1973,15 @@ void ComplexType::resolveSimpleTypeExtension() {
             basefield->setTypeValue(old_type);
             basefield->getEnumeration().modified = false;
           }
+          if (!hasRestrOrExt) {
+            st->addToNameDepList(basefield);
+            basefield->nameDep = st;
+          }
         }
       }
     } else if(!isBuiltInType(basefield->getType().convertedValue)){
          printError(module->getSchemaname(), name.convertedValue,
-          "Reference for a non-defined type: " + basefield->getReference().repr());
+          "Reference for a non-defined simpleType or complexType type: " + basefield->getReference().repr());
        TTCN3ModuleInventory::getInstance().incrNumErrors();
        return;
     }
@@ -1969,10 +1991,10 @@ void ComplexType::resolveSimpleTypeExtension() {
 
 void ComplexType::resolveSimpleTypeRestriction() {
   if (mode == restrictionMode && cmode == CT_simpletype_mode && basefield != NULL && !basefield->outside_reference.empty()) {
-    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(basefield, want_BOTH);
+    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(basefield, want_BOTH, c_simpleOrComplexType);
     if (st == NULL) {
       printError(module->getSchemaname(), name.convertedValue,
-        "Reference for a non-defined type: " + basefield->getReference().repr());
+        "Reference for a non-defined simpleType or complexType type: " + basefield->getReference().repr());
       TTCN3ModuleInventory::getInstance().incrNumErrors();
       return;
     }
@@ -2034,10 +2056,10 @@ void ComplexType::resolveSimpleTypeRestriction() {
         }
     }
   } else if (mode == restrictionMode && cmode == CT_simpletype_mode && basefield != NULL) {
-    ComplexType * ct = (ComplexType*) TTCN3ModuleInventory::getInstance().lookup(basefield, want_CT);
+    ComplexType * ct = (ComplexType*) TTCN3ModuleInventory::getInstance().lookup(basefield, want_CT, c_simpleOrComplexType);
     if (ct == NULL && !isBuiltInType(basefield->getType().convertedValue)) {
       printError(module->getSchemaname(), name.convertedValue,
-        "Reference for a non-defined type: " + basefield->getReference().repr());
+        "Reference for a non-defined simpleType or complexType type: " + basefield->getReference().repr());
       TTCN3ModuleInventory::getInstance().incrNumErrors();
       return;
     }
@@ -2070,10 +2092,10 @@ void ComplexType::resolveSimpleTypeRestriction() {
 
 void ComplexType::resolveComplexTypeExtension() {
   if (mode == extensionMode && cmode == CT_complextype_mode && !outside_reference.empty()) {
-    ComplexType * ct = (ComplexType*) TTCN3ModuleInventory::getInstance().lookup(this, want_CT);
+    ComplexType * ct = (ComplexType*) TTCN3ModuleInventory::getInstance().lookup(this, want_CT, c_simpleOrComplexType);
     if (ct == NULL) {
       printError(module->getSchemaname(), name.convertedValue,
-        "Reference for a non-defined type: " + getReference().repr());
+        "Reference for a non-defined simpleType or complexType type: " + getReference().repr());
       TTCN3ModuleInventory::getInstance().incrNumErrors();
       return;
     }
@@ -2149,10 +2171,10 @@ void ComplexType::resolveComplexTypeExtension() {
 
 void ComplexType::resolveComplexTypeRestriction() {
   if (mode == restrictionMode && cmode == CT_complextype_mode && !outside_reference.empty()) {
-    ComplexType * ct = (ComplexType*) TTCN3ModuleInventory::getInstance().lookup(this, want_CT);
+    ComplexType * ct = (ComplexType*) TTCN3ModuleInventory::getInstance().lookup(this, want_CT, c_simpleOrComplexType);
     if (ct == NULL) {
       printError(module->getSchemaname(), name.convertedValue,
-        "Reference for a non-defined type: " + getReference().repr());
+        "Reference for a non-defined simpleType or complexType type: " + getReference().repr());
       TTCN3ModuleInventory::getInstance().incrNumErrors();
       return;
     }
@@ -2247,8 +2269,16 @@ bool ComplexType::hasComplexRestriction(ComplexType* ct) const {
   return false;
 }
 
-void ComplexType::resolveUnion(SimpleType *st) {
+void ComplexType::resolveUnion() {
   if (parent != NULL && parent->with_union && xsdtype == n_simpleType && !outside_reference.empty()) {
+    SimpleType * st = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(this, want_BOTH, c_simpleType);
+    if (st == NULL && basefield == NULL) {
+      printError(module->getSchemaname(), name.convertedValue,
+        "Reference for a non-defined type: " + getReference().repr());
+      TTCN3ModuleInventory::getInstance().incrNumErrors();
+      outside_reference.set_resolved(NULL);
+      return;
+    }
     if (st->getXsdtype() != n_NOTSET) {
       ComplexType * ct = (ComplexType*) st;
       outside_reference.set_resolved(ct);
@@ -2386,14 +2416,14 @@ Mstring ComplexType::findRoot(const BlockValue block_value, SimpleType* elem, co
         if(ct->basefield != NULL && ct->basefield->getType().convertedValue.getValueWithoutPrefix(':') == head_type){
           return head_type;
         }else if(ct->basefield != NULL){
-          st = (SimpleType*)TTCN3ModuleInventory::getInstance().lookup(ct->basefield, want_BOTH);
+          st = (SimpleType*)TTCN3ModuleInventory::getInstance().lookup(ct->basefield, want_BOTH, c_unknown);
         }
       }
       if(st == NULL){
         st = (SimpleType*)(elem->getReference().get_ref());
       }
     }else if(elem->getMode() == noMode && (block_value == restriction || block_value == extension)){
-      st = (SimpleType*)TTCN3ModuleInventory::getInstance().lookup(this, elem->getType().convertedValue, want_BOTH);
+      st = (SimpleType*)TTCN3ModuleInventory::getInstance().lookup(this, elem->getType().convertedValue, want_BOTH, c_unknown);
     }
     if(st != NULL && elem != st){
       return findRoot(block_value, st, head_type, false);
diff --git a/xsdconvert/ComplexType.hh b/xsdconvert/ComplexType.hh
index 742bd4b630448bd8dab7546d9cddcb4b04e7759b..1743ae734674bb717c716262ed3f22e102836de0 100644
--- a/xsdconvert/ComplexType.hh
+++ b/xsdconvert/ComplexType.hh
@@ -79,7 +79,6 @@ private:
   TagName lastType;
   Mstring actualPath;
   RootType * actfield;
-  SimpleType * nameDep; // not owned
   RootType * nillable_field;
   ComplexType * basefield;
   ComplexType_Mode cmode;
@@ -108,14 +107,14 @@ private:
   //Reference resolving functions
   void reference_resolving_funtion();
   void resolveAttribute(AttributeType *attr);
-  void resolveAttributeGroup(SimpleType *st);
-  void resolveGroup(SimpleType *st);
-  void resolveElement(SimpleType *st);
+  void resolveAttributeGroup();
+  void resolveGroup();
+  void resolveElement();
   void resolveSimpleTypeExtension();
   void resolveSimpleTypeRestriction();
   void resolveComplexTypeExtension();
   void resolveComplexTypeRestriction();
-  void resolveUnion(SimpleType *st);
+  void resolveUnion();
   bool hasMatchingFields(const List<ComplexType*>& a, const List<ComplexType*>& b) const;
   // True if a restriction really restricts the type not just aliases
   bool hasComplexRestriction(ComplexType* ct) const;
diff --git a/xsdconvert/GeneralFunctions.cc b/xsdconvert/GeneralFunctions.cc
index d10ee1b9e7c03a28316221e59356a9a34d99a45e..a4682f0c9ada59128b59930357fd8e45949f9462 100644
--- a/xsdconvert/GeneralFunctions.cc
+++ b/xsdconvert/GeneralFunctions.cc
@@ -666,7 +666,7 @@ const Mstring& getPrefixByNameSpace(const RootType * root, const Mstring& namesp
 }
 
 const Mstring findBuiltInType(const RootType* ref, Mstring type){
-  RootType * root = TTCN3ModuleInventory::getInstance().lookup(ref, type, want_BOTH);
+  RootType * root = TTCN3ModuleInventory::getInstance().lookup(ref, type, want_BOTH, c_unknown);
   if(root != NULL && isBuiltInType(root->getType().originalValueWoPrefix)){
     return root->getType().originalValueWoPrefix;
   }else if(root != NULL){
@@ -676,18 +676,18 @@ const Mstring findBuiltInType(const RootType* ref, Mstring type){
   }
 }
 
-RootType * lookup(const List<TTCN3Module*> mods, const SimpleType * reference, wanted w) {
+RootType * lookup(const List<TTCN3Module*> mods, const SimpleType * reference, wanted w, ConstructType construct) {
   const Mstring& uri = reference->getReference().get_uri();
   const Mstring& name = reference->getReference().get_val();
 
-  return lookup(mods, name, uri, reference, w);
+  return lookup(mods, name, uri, reference, w, construct);
 }
 
 RootType * lookup(const List<TTCN3Module*> mods,
-  const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w) {
+  const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w, ConstructType construct) {
   RootType *ret = NULL;
   for (List<TTCN3Module*>::iterator module = mods.begin(); module; module = module->Next) {
-    ret = lookup1(module->Data, name, nsuri, reference, w);
+    ret = lookup1(module->Data, name, nsuri, reference, w, construct);
     if (ret != NULL) break;
   } // next doc
 
@@ -695,14 +695,26 @@ RootType * lookup(const List<TTCN3Module*> mods,
 }
 
 RootType *lookup1(const TTCN3Module *module,
-  const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w) {
+  const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w, ConstructType construct) {
   if (nsuri != module->getTargetNamespace()) return NULL;
-      
+  
   for (List<RootType*>::iterator type = module->getDefinedTypes().begin(); type; type = type->Next) {
-    switch (type->Data->getConstruct()) {
+    switch (type->Data->getNewConstruct()) {
       case c_simpleType:
+        if (construct != c_simpleType && construct != c_simpleOrComplexType && construct != c_unknown) {
+          break;
+        }
+        goto wantST;
       case c_element:
+        if (construct != c_element && construct != c_unknown) {
+          break;
+        }
+        goto wantST;
       case c_attribute:
+        if (construct != c_attribute && construct != c_unknown) {
+          break;
+        }
+wantST:
         if (w == want_ST || w == want_BOTH) {
           if ((const RootType*) reference != type->Data
             && name == type->Data->getName().originalValueWoPrefix) {
@@ -712,8 +724,20 @@ RootType *lookup1(const TTCN3Module *module,
         break;
 
       case c_complexType:
+        if (construct != c_complexType && construct != c_simpleOrComplexType && construct != c_unknown) {
+          break;
+        }
+        goto wantCT;
       case c_group:
+        if (construct != c_group && construct != c_unknown) {
+          break;
+        }
+        goto wantCT;
       case c_attributeGroup:
+        if (construct != c_attributeGroup && construct != c_unknown) {
+          break;
+        }
+wantCT:
         if (w == want_CT || w == want_BOTH) {
           if ((const RootType*) reference != type->Data
             && name == type->Data->getName().originalValueWoPrefix) {
@@ -733,7 +757,7 @@ RootType *lookup1(const TTCN3Module *module,
     if (it->Data != NULL && it->Data->getConstruct() == c_include &&
         ((ImportStatement*)(it->Data))->getSourceModule() != NULL &&
         ((ImportStatement*)(it->Data))->getSourceModule()->getTargetNamespace() == Mstring("NoTargetNamespace")) {
-      return lookup1(((ImportStatement*)(it->Data))->getSourceModule(), name, Mstring("NoTargetNamespace"), reference, w);
+      return lookup1(((ImportStatement*)(it->Data))->getSourceModule(), name, Mstring("NoTargetNamespace"), reference, w, construct);
     }
   }
   return NULL;
@@ -743,8 +767,8 @@ int multi(const TTCN3Module *module, ReferenceData const& outside_reference,
   const RootType *obj) {
   int multiplicity = 0;
 
-  RootType * st = ::lookup1(module, outside_reference.get_val(), outside_reference.get_uri(), obj, want_ST);
-  RootType * ct = ::lookup1(module, outside_reference.get_val(), outside_reference.get_uri(), obj, want_CT);
+  RootType * st = ::lookup1(module, outside_reference.get_val(), outside_reference.get_uri(), obj, want_ST, c_unknown);
+  RootType * ct = ::lookup1(module, outside_reference.get_val(), outside_reference.get_uri(), obj, want_CT, c_unknown);
   if (st || ct) {
     multiplicity = 1; // locally defined, no qualif needed
     // means that outside_reference.get_uri() == module->getTargetNamespace())
@@ -752,8 +776,8 @@ int multi(const TTCN3Module *module, ReferenceData const& outside_reference,
     // Look for definitions in the imported modules
     for (List<const TTCN3Module*>::iterator it = module->getImportedModules().begin(); it; it = it->Next) {
       // Artificial lookup
-      st = ::lookup1(it->Data, outside_reference.get_val(), it->Data->getTargetNamespace(), obj, want_ST);
-      ct = ::lookup1(it->Data, outside_reference.get_val(), it->Data->getTargetNamespace(), obj, want_CT);
+      st = ::lookup1(it->Data, outside_reference.get_val(), it->Data->getTargetNamespace(), obj, want_ST, c_unknown);
+      ct = ::lookup1(it->Data, outside_reference.get_val(), it->Data->getTargetNamespace(), obj, want_CT, c_unknown);
       if (st || ct) {
         ++multiplicity;
       }
@@ -762,8 +786,8 @@ int multi(const TTCN3Module *module, ReferenceData const& outside_reference,
     // But if == 1 we need to check this module for a type definition with
     // the same name as outsize_reference.get_val()
     if (multiplicity == 1) {
-      st = ::lookup1(module, outside_reference.get_val(), module->getTargetNamespace(), obj, want_ST);
-      ct = ::lookup1(module, outside_reference.get_val(), module->getTargetNamespace(), obj, want_CT);
+      st = ::lookup1(module, outside_reference.get_val(), module->getTargetNamespace(), obj, want_ST, c_unknown);
+      ct = ::lookup1(module, outside_reference.get_val(), module->getTargetNamespace(), obj, want_CT, c_unknown);
       if (st || ct) {
         ++multiplicity;
       }
diff --git a/xsdconvert/GeneralFunctions.hh b/xsdconvert/GeneralFunctions.hh
index 80ae8772761b5faf1582851e3235cdcf94ebac66..74429927b047cc4e2ef497b7b6d01e4229c86bcc 100644
--- a/xsdconvert/GeneralFunctions.hh
+++ b/xsdconvert/GeneralFunctions.hh
@@ -66,13 +66,13 @@ const Mstring findBuiltInType(const RootType * ref, Mstring type);
 
 /// Lookup in a list of modules
 RootType * lookup(const List<TTCN3Module*> mods,
-        const SimpleType * reference, wanted w);
+        const SimpleType * reference, wanted w, ConstructType construct);
 /// Lookup in a list of modules
 RootType * lookup(const List<TTCN3Module*> mods,
-        const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w);
+        const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w, ConstructType construct);
 /// Lookup inside one module
 RootType *lookup1(const TTCN3Module *module,
-        const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w);
+        const Mstring& name, const Mstring& nsuri, const RootType *reference, wanted w, ConstructType construct);
 
 int multi(const TTCN3Module *module, ReferenceData const& outside_reference,
         const RootType *obj);
diff --git a/xsdconvert/GeneralTypes.hh b/xsdconvert/GeneralTypes.hh
index 484db2fcd9a5c466f52e588e92d2e5ac78d24ca4..27dbd8391e979246e178abd3871fd7681bdb98e7 100644
--- a/xsdconvert/GeneralTypes.hh
+++ b/xsdconvert/GeneralTypes.hh
@@ -30,7 +30,8 @@ enum ConstructType {
   c_annotation,
   c_include,
   c_import,
-  c_idattrib
+  c_idattrib,
+  c_simpleOrComplexType
 };
 
 enum NameConversionMode {
diff --git a/xsdconvert/RootType.cc b/xsdconvert/RootType.cc
index 6b2ea2cc0ccd9184b1519f16fd21b399e0df646b..2e13131e773aaf2b7a012a5fe9a29634aa1acc49 100644
--- a/xsdconvert/RootType.cc
+++ b/xsdconvert/RootType.cc
@@ -25,6 +25,7 @@ RootType::RootType(XMLParser * a_parser, TTCN3Module * a_module, const Construct
 , variant_ref()
 , comment()
 , construct(a_construct)
+, new_construct(a_construct)
 , origin(from_unknown)
 , visible(true)
 , nameDepList()
diff --git a/xsdconvert/RootType.hh b/xsdconvert/RootType.hh
index 4251d324314333390ac0d8afcff38b46b15ba432..00be148705ad023d7ed343063c5514c4bfe53e9a 100644
--- a/xsdconvert/RootType.hh
+++ b/xsdconvert/RootType.hh
@@ -138,7 +138,9 @@ protected:
   List<Mstring> hidden_variant;
   List<Mstring> comment;
 
-  ConstructType construct;
+  ConstructType construct; // It should not be modified because the nameconversion
+                           // is dependent on this and causes backward incompatibility
+  ConstructType new_construct; // It is used to make the lookup() function more accurate
   OriginType origin;
   bool visible;
 
@@ -253,6 +255,10 @@ public:
   ConstructType getConstruct() const {
     return construct;
   }
+  
+  ConstructType getNewConstruct() const {
+    return new_construct;
+  }
 
   OriginType getOrigin() const {
     return origin;
diff --git a/xsdconvert/SimpleType.cc b/xsdconvert/SimpleType.cc
index 83397ab925c2da25ba4f494dbe5d9889e2ebfab3..6d605410f99b685913ca985b8f1f079646156488 100644
--- a/xsdconvert/SimpleType.cc
+++ b/xsdconvert/SimpleType.cc
@@ -66,7 +66,8 @@ SimpleType::SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructTy
 , inList(false)
 , alias(NULL)
 , defaultForEmptyConstant(NULL)
-, parent(NULL) {
+, parent(NULL)
+, nameDep(NULL) {
 }
 
 SimpleType::SimpleType(const SimpleType& other)
@@ -93,12 +94,17 @@ SimpleType::SimpleType(const SimpleType& other)
 , inList(other.inList)
 , alias(other.alias)
 , defaultForEmptyConstant(other.defaultForEmptyConstant)
-, parent(NULL) {
+, parent(NULL)
+, nameDep(other.nameDep) {
   length.parent = this;
   pattern.parent = this;
   enumeration.parent = this;
   whitespace.p_parent = this;
   value.parent = this;
+  
+  if (nameDep != NULL) {
+    nameDep->addToNameDepList(this);
+  }
 }
 
 void SimpleType::loadWithValues() {
@@ -323,7 +329,7 @@ void SimpleType::addToSubstitutions(){
   if(!g_flag_used || substitutionGroup.empty()){
     return;
   }
-  SimpleType * st_ = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(this, substitutionGroup, want_BOTH);
+  SimpleType * st_ = (SimpleType*) TTCN3ModuleInventory::getInstance().lookup(this, substitutionGroup, want_BOTH, c_element);
   if(st_ == NULL){
     printError(module->getSchemaname(), name.convertedValue,
         "Reference for a non-defined type: " + substitutionGroup);
@@ -337,7 +343,7 @@ void SimpleType::addToSubstitutions(){
 
   st->referenceResolving();
   substitutionGroup = empty_string;
-  //Simpletype
+  //SimpleType
   if(st->subsGroup == NULL){
     ComplexType * head_element = new ComplexType(*st, ComplexType::fromElementSubstitution);
     for(List<RootType*>::iterator simpletype = st->nameDepList.begin(); simpletype; simpletype = simpletype->Next){
@@ -450,7 +456,7 @@ void SimpleType::collectElementTypes(SimpleType* found_ST, ComplexType* found_CT
   //Only if type substitution is enabled and it is a top level(simpletype) element or
   //it is a not top level element(complextype)
   if(h_flag_used && (hasVariant(Mstring("\"element\"")) || xsdtype == n_element)){
-    SimpleType * st =  NULL, *nameDep = NULL;
+    SimpleType * st =  NULL, *nameDepType = NULL;
     Mstring uri, value_, type_;
     if(found_ST != NULL || found_CT != NULL){
       // st := found_ST or found_CT, which is not null
@@ -464,7 +470,7 @@ void SimpleType::collectElementTypes(SimpleType* found_ST, ComplexType* found_CT
       value_ = type.convertedValue;
       if(outside_reference.empty()){
         type_ = value_;
-        nameDep = this;
+        nameDepType = this;
       }else {
         type_ = outside_reference.get_val();
       }
@@ -482,7 +488,7 @@ void SimpleType::collectElementTypes(SimpleType* found_ST, ComplexType* found_CT
         complex->Data->setVisible();
         if(st->getXsdtype() != n_NOTSET && this == st){ //otherwise records would be renamed too
           complex->Data->addToNameDepList(st);
-          ((ComplexType*)st)->setNameDep(nameDep);
+          ((ComplexType*)st)->setNameDep(nameDepType);
         }
         found = true;
         break;
@@ -494,7 +500,7 @@ void SimpleType::collectElementTypes(SimpleType* found_ST, ComplexType* found_CT
       if(prefix != empty_string){
         prefix += ":";
       }
-      st->getModule()->addElementType(prefix + type_, nameDep);
+      st->getModule()->addElementType(prefix + type_, nameDepType);
     }
   }
 }
@@ -591,11 +597,16 @@ void SimpleType::referenceResolving() {
   
   if(!outside_reference.empty()){
     SimpleType * found_ST = static_cast<SimpleType*> (
-      TTCN3ModuleInventory::getInstance().lookup(this, want_ST));
+      TTCN3ModuleInventory::getInstance().lookup(this, want_ST, c_simpleType));
     ComplexType * found_CT = static_cast<ComplexType*> (
-      TTCN3ModuleInventory::getInstance().lookup(this, want_CT));
+      TTCN3ModuleInventory::getInstance().lookup(this, want_CT, c_complexType));
     // It _is_ possible to find both
     collectElementTypes(found_ST, found_CT);
+    // If found_ST is a complexType with an xsd:union restricted to certain values
+    if (found_ST != NULL && found_ST->getType().convertedValue == Mstring("union") && mode == restrictionMode) {
+      found_CT = (ComplexType*)found_ST;
+      found_ST = NULL;
+    }
     if (found_ST != NULL) {
       if (!found_ST->outside_reference.empty() && !found_ST->outside_reference.is_resolved() && found_ST != this) {
         found_ST->referenceResolving();
@@ -614,9 +625,9 @@ void SimpleType::referenceResolving() {
       if (!isBuiltInType(type.convertedValue)) {
         found_CT->addToNameDepList(this);
       }
-    }else {
+    } else {
       printError(module->getSchemaname(), name.convertedValue,
-        "Reference for a non-defined type: " + outside_reference.repr());
+        "Reference for a non-defined simpleType or complexType type: " + outside_reference.repr());
       TTCN3ModuleInventory::getInstance().incrNumErrors();
       outside_reference.set_resolved(NULL);
     }
@@ -1251,7 +1262,7 @@ void EnumerationType::applyReference(const EnumerationType & other) {
 void EnumerationType::applyFacets() // string types, integer types, float types, time types
 {
   if (!modified) return;
-
+  
   facets.remove_dups();
 
   const Mstring & base = parent->getBuiltInBase();
diff --git a/xsdconvert/SimpleType.hh b/xsdconvert/SimpleType.hh
index e3714960563ff58fa4e7565ef534a6cd33dd3c35..2ae8964721430bc83d0a5ff0bf9f7718640a41ce 100644
--- a/xsdconvert/SimpleType.hh
+++ b/xsdconvert/SimpleType.hh
@@ -275,6 +275,8 @@ public:
   // Parent of the element (both complexType, and AttributeType) has this
   // Not responsible for this member
   ComplexType * parent;
+  
+  SimpleType * nameDep; // not owned
 
   /** Virtual methods
    *  inherited from RootType
diff --git a/xsdconvert/TTCN3Module.cc b/xsdconvert/TTCN3Module.cc
index b503dbedb9e40e4537b4b9c0a7c91ddd5211e34f..7397156ba10f44647f1d774579ebc1cc1304b7dc 100644
--- a/xsdconvert/TTCN3Module.cc
+++ b/xsdconvert/TTCN3Module.cc
@@ -220,6 +220,7 @@ void TTCN3Module::addMainType(const ConstructType typeOfMainType) {
     }
     case c_unknown:
     case c_schema:
+    case c_simpleOrComplexType:
       break;
   }
 
diff --git a/xsdconvert/TTCN3ModuleInventory.cc b/xsdconvert/TTCN3ModuleInventory.cc
index bed82138be9aae783a214171c7849694219570ea..4051f0bef6c0d3fca30b0e113051f17b1554919d 100644
--- a/xsdconvert/TTCN3ModuleInventory.cc
+++ b/xsdconvert/TTCN3ModuleInventory.cc
@@ -341,7 +341,7 @@ void TTCN3ModuleInventory::printModuleNames() const {
   }
 }
 
-RootType * TTCN3ModuleInventory::lookup(const RootType* ref, const Mstring& reference, wanted w) const {
+RootType * TTCN3ModuleInventory::lookup(const RootType* ref, const Mstring& reference, wanted w, ConstructType construct) const {
   Mstring uri = reference.getPrefix(':');
   const Mstring& name = reference.getValueWithoutPrefix(':');
   if(uri.empty()){
@@ -358,26 +358,26 @@ RootType * TTCN3ModuleInventory::lookup(const RootType* ref, const Mstring& refe
   }else {
     uri = getNameSpaceByPrefix(ref, uri);
   }
-  return lookup(name, uri, NULL, w);
+  return lookup(name, uri, NULL, w, construct);
 }
 
-RootType * TTCN3ModuleInventory::lookup(const SimpleType * reference, wanted w) const {
+RootType * TTCN3ModuleInventory::lookup(const SimpleType * reference, wanted w, ConstructType construct) const {
   const Mstring& uri = reference->getReference().get_uri();
   const Mstring& name = reference->getReference().get_val();
 
-  return lookup(name, uri, reference, w);
+  return lookup(name, uri, reference, w, construct);
 }
 
-RootType * TTCN3ModuleInventory::lookup(const ComplexType * reference, wanted w) const {
+RootType * TTCN3ModuleInventory::lookup(const ComplexType * reference, wanted w, ConstructType construct) const {
   const Mstring& uri = reference->getReference().get_uri();
   const Mstring& name = reference->getReference().get_val();
 
-  return lookup(name, uri, reference, w);
+  return lookup(name, uri, reference, w, construct);
 }
 
 RootType * TTCN3ModuleInventory::lookup(const Mstring& name, const Mstring& nsuri,
-  const RootType *reference, wanted w) const {
-  return ::lookup(definedModules, name, nsuri, reference, w);
+  const RootType *reference, wanted w, ConstructType construct) const {
+  return ::lookup(definedModules, name, nsuri, reference, w, construct);
 }
 
 void TTCN3ModuleInventory::dump() const {
diff --git a/xsdconvert/TTCN3ModuleInventory.hh b/xsdconvert/TTCN3ModuleInventory.hh
index fea0eead60af5d311a5ced8e255a727bb1b53cf1..06f45b27a3b1e903bd38e6e0dad506ebb71ec60c 100644
--- a/xsdconvert/TTCN3ModuleInventory.hh
+++ b/xsdconvert/TTCN3ModuleInventory.hh
@@ -107,11 +107,11 @@ public:
    * Searching methods
    * Look for a simpleType (or element or attribute) or a complexType (or attributeGroup or group)
    */
-  RootType * lookup(const RootType * ref, const Mstring& reference, wanted w) const;
-  RootType * lookup(const SimpleType * reference, wanted w) const;
-  RootType * lookup(const ComplexType * reference, wanted w) const;
+  RootType * lookup(const RootType * ref, const Mstring& reference, wanted w, ConstructType construct) const;
+  RootType * lookup(const SimpleType * reference, wanted w, ConstructType construct) const;
+  RootType * lookup(const ComplexType * reference, wanted w, ConstructType construct) const;
   RootType * lookup(const Mstring& name, const Mstring& nsuri,
-      const RootType *reference, wanted w) const;
+      const RootType *reference, wanted w, ConstructType construct) const;
 
   static unsigned int getNumErrors() {
     return num_errors;