diff --git a/girepository/girparser.c b/girepository/girparser.c
index d4cc34a..ca5e405 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -43,9 +43,11 @@ typedef enum
   STATE_CLASS,  
   STATE_CLASS_FIELD,
   STATE_CLASS_PROPERTY,
+  STATE_CLASS_STRUCT,
   STATE_INTERFACE,
   STATE_INTERFACE_PROPERTY,   /* 15 */
   STATE_INTERFACE_FIELD,
+  STATE_INTERFACE_STRUCT,
   STATE_IMPLEMENTS, 
   STATE_REQUIRES,
   STATE_BOXED,  
@@ -556,6 +558,9 @@ start_function (GMarkupParseContext *context,
 	       strcmp (element_name, "method") == 0 ||
 	       strcmp (element_name, "callback") == 0);
       break;
+    case STATE_CLASS_STRUCT:
+    case STATE_INTERFACE_STRUCT:
+      return TRUE;
     default:
       break;
     }
@@ -674,6 +679,10 @@ start_parameter (GMarkupParseContext *context,
   const gchar *nullok;
   const gchar *transfer;
   GIrNodeParam *param;
+
+  if (ctx->state == STATE_CLASS_STRUCT ||
+      ctx->state == STATE_INTERFACE_STRUCT)
+    return TRUE;
       
   if (!(strcmp (element_name, "parameter") == 0 &&
 	ctx->state == STATE_FUNCTION_PARAMETERS))
@@ -819,6 +828,9 @@ start_field (GMarkupParseContext *context,
     case STATE_UNION:
     case STATE_INTERFACE:
       break;
+    case STATE_CLASS_STRUCT:
+    case STATE_INTERFACE_STRUCT:
+      return TRUE;
     default:
       return FALSE;
     }
@@ -1430,6 +1442,10 @@ start_type (GMarkupParseContext *context,
   if (!(is_array || is_varargs || (strcmp (element_name, "type") == 0)))
     return FALSE;
 
+  if (ctx->state == STATE_CLASS_STRUCT ||
+      ctx->state == STATE_INTERFACE_STRUCT)
+    return TRUE;
+
   if (ctx->state == STATE_TYPE) 
     {
       ctx->type_depth++;
@@ -1536,6 +1552,10 @@ end_type_top (ParseContext *ctx)
 {
   GIrNodeType *typenode;
 
+  if (ctx->state == STATE_CLASS_STRUCT ||
+      ctx->state == STATE_INTERFACE_STRUCT)
+    goto out;
+
   if (!ctx->type_parameters)
     goto out;
 
@@ -1602,6 +1622,10 @@ end_type_recurse (ParseContext *ctx)
   GList *types;
   GIrNodeType *parent;
 
+  if (ctx->state == STATE_CLASS_STRUCT ||
+      ctx->state == STATE_INTERFACE_STRUCT)
+    return;
+
   parent = (GIrNodeType *) ((GList*)ctx->type_stack->data)->data;
 
   if (parent->tag == GI_TYPE_TAG_ARRAY ||
@@ -1654,6 +1678,11 @@ start_return_value (GMarkupParseContext *context,
 		    ParseContext       *ctx,
 		    GError             **error)
 {
+
+  if (ctx->state == STATE_CLASS_STRUCT ||
+      ctx->state == STATE_INTERFACE_STRUCT)
+    return TRUE;
+
   if (strcmp (element_name, "return-value") == 0 &&
       ctx->state == STATE_FUNCTION)
     {
@@ -1898,8 +1927,20 @@ start_struct (GMarkupParseContext *context,
 	      ParseContext       *ctx,
 	      GError             **error)
 {
-  if (strcmp (element_name, "record") == 0 && 
-      ctx->state == STATE_NAMESPACE)
+  if (strcmp (element_name, "record") != 0)
+    return FALSE;
+  
+  if (ctx->state == STATE_INTERFACE)
+    {
+      state_switch (ctx, STATE_INTERFACE_STRUCT);
+      return TRUE;
+    }
+  if (ctx->state == STATE_CLASS)
+    {
+      state_switch (ctx, STATE_CLASS_STRUCT);
+      return TRUE;
+    }
+  if (ctx->state == STATE_NAMESPACE)
     {
       const gchar *name;
       const gchar *deprecated;
@@ -2437,9 +2478,23 @@ end_element_handler (GMarkupParseContext *context,
 		     GError             **error)
 {
   ParseContext *ctx = user_data;
+  gboolean is_record = strcmp (element_name, "record") == 0;
 
   g_debug ("</%s>", element_name);
 
+  if (ctx->state == STATE_CLASS_STRUCT)
+    {
+      if (is_record)
+	state_switch (ctx, STATE_CLASS);
+      return;
+    }
+  else if (ctx->state == STATE_INTERFACE_STRUCT)
+    {
+      if (is_record)
+	state_switch (ctx, STATE_INTERFACE);
+      return;
+    }
+
   switch (ctx->state)
     {
     case STATE_START:
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 6f2e9c2..6a3bb8d 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -290,6 +290,7 @@ class Class(Node):
     def __init__(self, name, parent):
         Node.__init__(self, name)
         self.ctype = name
+        self.class_struct = None
         self.parent = parent
         self.methods = []
         self.interfaces = []
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index fa7c0e5..c096c15 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -226,6 +226,8 @@ class GIRWriter(XMLWriter):
                 for iface in node.interfaces:
                     self.write_tag('implements', [('name', iface)])
             if isinstance(node, Class):
+                if node.class_struct:
+                    self._write_record(node.class_struct)
                 for method in node.constructors:
                     self._write_constructor(method)
             for method in node.methods:
diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py
index fdae652..2588f1c 100644
--- a/giscanner/glibtransformer.py
+++ b/giscanner/glibtransformer.py
@@ -458,18 +458,28 @@ class GLibTransformer(object):
 
         name = self._resolve_type_name(name)
         resolved = self._transformer.strip_namespace_object(name)
+        print "LOOKING FOR PAIR: %r: %r" % (maybe_class, resolved)
         pair_class = self._get_attribute(resolved)
         if pair_class and isinstance(pair_class,
                                      (GLibObject, GLibInterface)):
-            for field in maybe_class.fields[1:]:
-                pair_class.fields.append(field)
+            print "PAIRED: %r" % (pair_class, )
+            pair_class.class_struct = maybe_class
+            self._remove_attribute(maybe_class.name)
+            return
+        # This is a floating class structure with no pair - we just delete
+        # it for now.
+        if self._namespace_name not in ('GLib', 'GObject') and \
+                maybe_class.fields and \
+                maybe_class.fields[0].type.name.endswith('Class'):
+            print "Warning: removing floating class structure %r" \
+                % (maybe_class, )
+            self._remove_attribute(maybe_class.name)
             return
         name = self._transformer.strip_namespace_object(maybe_class.name)
         pair_class = self._get_attribute(name)
         if pair_class and isinstance(pair_class,
                                      (GLibObject, GLibInterface)):
-
-            del self._names.names[maybe_class.name]
+            self._remove_attribute(maybe_class.name)
 
     # Introspection
 
