diff --git a/gobject/gtype.c b/gobject/gtype.c
index 8c8fc41..2fede91 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -2369,7 +2369,8 @@ g_type_class_ref (GType type)
   G_WRITE_LOCK (&type_rw_lock);
   node = lookup_type_node_I (type);
   if (node && node->is_classed && node->data &&
-      node->data->class.class && node->data->common.ref_count > 0)
+      node->data->class.init_state == INITIALIZED &&
+      node->data->common.ref_count > 0)
     {
       type_data_ref_Wm (node);
       G_WRITE_UNLOCK (&type_rw_lock);
@@ -2387,13 +2388,13 @@ g_type_class_ref (GType type)
     }
 
   type_data_ref_Wm (node);
+  G_WRITE_UNLOCK (&type_rw_lock);
+  g_static_rec_mutex_lock (&class_init_rec_mutex); /* required locking order: 1) class_init_rec_mutex, 2) type_rw_lock */
 
   if (!node->data->class.class) /* class uninitialized */
     {
       GType ptype = NODE_PARENT_TYPE (node);
       GTypeClass *pclass = NULL;
-      G_WRITE_UNLOCK (&type_rw_lock);
-      g_static_rec_mutex_lock (&class_init_rec_mutex); /* required locking order: 1) class_init_rec_mutex, 2) type_rw_lock */
       if (ptype)
         {
           pclass = g_type_class_ref (ptype);
@@ -2407,11 +2408,10 @@ g_type_class_ref (GType type)
           G_WRITE_LOCK (&type_rw_lock);
           node = lookup_type_node_I (type);
         }
-      if (!node->data->class.class) /* class could have been initialized meanwhile */
-        type_class_init_Wm (node, pclass);
+      type_class_init_Wm (node, pclass);
       G_WRITE_UNLOCK (&type_rw_lock);
-      g_static_rec_mutex_unlock (&class_init_rec_mutex);
     }
+  g_static_rec_mutex_unlock (&class_init_rec_mutex);
   return node->data->class.class;
 }
 
@@ -2461,7 +2461,8 @@ g_type_class_peek (GType type)
   
   node = lookup_type_node_I (type);
   G_READ_LOCK (&type_rw_lock);
-  if (node && node->is_classed && node->data && node->data->class.class) /* common.ref_count _may_ be 0 */
+  if (node && node->is_classed && node->data &&
+      node->data->class.init_state == INITIALIZED) /* common.ref_count _may_ be 0 */
     class = node->data->class.class;
   else
     class = NULL;
@@ -2480,7 +2481,7 @@ g_type_class_peek_static (GType type)
   G_READ_LOCK (&type_rw_lock);
   if (node && node->is_classed && node->data &&
       /* peek only static types: */ node->plugin == NULL &&
-      node->data->class.class) /* common.ref_count _may_ be 0 */
+      node->data->class.init_state == INITIALIZED) /* common.ref_count _may_ be 0 */
     class = node->data->class.class;
   else
     class = NULL;
