Index: trunk/src/gfx/texture_font.cc
===================================================================
--- trunk/src/gfx/texture_font.cc	(revision 252)
+++ trunk/src/gfx/texture_font.cc	(revision 256)
@@ -92,5 +92,5 @@
 }
 
-bool texture_font::load_glyphs( const std::string& codes )
+bool texture_font::load_glyphs( const string& codes )
 {
 	FT_Face face     = (FT_Face)(m_rface);
Index: trunk/src/library.cc
===================================================================
--- trunk/src/library.cc	(revision 252)
+++ trunk/src/library.cc	(revision 256)
@@ -4,6 +4,4 @@
 #include "nv/common.hh"
 #include "nv/library.hh"
-
-#include <string.h>
 
 #if NV_PLATFORM == NV_WINDOWS
@@ -41,5 +39,5 @@
 }
 
-void library::open( const std::string& name )
+void library::open( const string& name )
 {
 	m_name = name;
@@ -51,5 +49,5 @@
 }
 
-bool nv::library::try_open( const std::string& name )
+bool nv::library::try_open( const string& name )
 {
 	m_name = name;
@@ -62,5 +60,5 @@
 }
 
-const std::string& library::get_name() const
+const string& library::get_name() const
 {
     return m_name;
@@ -75,6 +73,6 @@
     NV_LOG( LOG_NOTICE, "library : loading '" + m_name + "'..." );
 
-    std::string name = m_name;
-    std::string ext  = NV_LIB_EXT;
+    string name = m_name;
+    string ext  = NV_LIB_EXT;
     size_t ext_len   = ext.length();
 
@@ -95,5 +93,5 @@
 }
 
-void* library::get( const std::string& symbol )
+void* library::get( const string& symbol )
 {
 	void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
@@ -105,5 +103,5 @@
 }
 
-void* nv::library::try_get( const std::string& symbol )
+void* nv::library::try_get( const string& symbol )
 {
 	return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
@@ -133,5 +131,5 @@
 }
 
-std::string library::get_error()
+string library::get_error()
 {
 #if NV_PLATFORM == NV_WINDOWS
@@ -140,11 +138,11 @@
     FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
         NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );
-    std::string msg( (char*)buffer );
+    string msg( (char*)buffer );
     LocalFree( buffer );
     return msg;
 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
-    return std::string(dlerror());
+    return string(dlerror());
 #else
-    return std::string("");
+    return string("");
 #endif
 }
Index: trunk/src/lua/lua_state.cc
===================================================================
--- trunk/src/lua/lua_state.cc	(revision 252)
+++ trunk/src/lua/lua_state.cc	(revision 256)
@@ -383,12 +383,18 @@
 {
 	if (!o) return;
+	unregister_object( o->get_lua_index() );
+}
+
+void lua::state::unregister_object( int index )
+{
 	stack_guard guard( this );
-	lua_rawgeti( m_state, LUA_REGISTRYINDEX, o->get_lua_index() );
+	lua_rawgeti( m_state, LUA_REGISTRYINDEX, index );
 	lua_pushstring( m_state, "__ptr" );
 	lua_pushboolean( m_state, false );
 	lua_rawset( m_state, -3 );
 	lua_pop( m_state, 1 );
-	luaL_unref( m_state, LUA_REGISTRYINDEX, o->get_lua_index() );
-}
+	luaL_unref( m_state, LUA_REGISTRYINDEX, index );
+}
+
 
 void lua::state::deep_pointer_copy( int index, void* obj )
Index: trunk/src/object.cc
===================================================================
--- trunk/src/object.cc	(revision 252)
+++ trunk/src/object.cc	(revision 256)
@@ -41,11 +41,6 @@
 	if ( m_root )
 	{
-		uid_store*  store = get_root()->get_uid_store();
-		if (store)
-		{
-			m_uid = store->insert( this );
-		}
-	}
-
+		m_root->object_created( this );
+	}
 }
 
@@ -104,13 +99,7 @@
 object::~object()
 {
- 	if ( m_lua_index != lua::ref_none )
- 	{
-		lua::state* state = get_root()->get_lua_state();
- 		state->unregister_object( this );
- 	}
-	if ( m_uid != 0 && m_root )
-	{
-		uid_store* store = get_root()->get_uid_store();
-		if (store) store->remove( m_uid );
+	if ( m_root )
+	{
+		m_root->object_destroyed( this );
 	}
 	detach();
@@ -194,16 +183,16 @@
 }
 
-void object::register_type( type_database* db )
-{
-	type_field fields[] = {
-		type_field("id",          &object::m_id),
-		type_field("uid",         &object::m_uid).flag( TF_READONLY ), 
-		type_field("lua_index",   &object::m_lua_index).flag( TF_READONLY | TF_NOSERIALIZE ),
-		type_field("parent",      &object::m_parent).flag( TF_READONLY | TF_NOSERIALIZE ),
-		type_field("child_count", &object::m_child_count).flag( TF_READONLY ),
-		type_field("children"   , &object::m_children).flag( TF_READONLY ),
-	};
-	db->create_type<object>("object").fields(fields);
-}
+// void object::register_type( type_database* db )
+// {
+// 	type_field fields[] = {
+// 		type_field("id",          &object::m_id),
+// 		type_field("uid",         &object::m_uid).flag( TF_READONLY ), 
+// 		type_field("lua_index",   &object::m_lua_index).flag( TF_READONLY | TF_NOSERIALIZE ),
+// 		type_field("parent",      &object::m_parent).flag( TF_READONLY | TF_NOSERIALIZE ),
+// 		type_field("child_count", &object::m_child_count).flag( TF_READONLY ),
+// 		type_field("children"   , &object::m_children).flag( TF_READONLY ),
+// 	};
+// 	db->create_type<object>("object").fields(fields);
+// }
 
 void nv::object::register_with_lua( const char* lua_name, const char* storage )
Index: trunk/src/root.cc
===================================================================
--- trunk/src/root.cc	(revision 252)
+++ trunk/src/root.cc	(revision 256)
@@ -0,0 +1,30 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/root.hh"
+
+#include "nv/uid.hh"
+#include "nv/lua/lua_state.hh"
+
+void nv::root::object_created( object* o )
+{
+	if ( m_uid_store )
+	{
+		o->m_uid = m_uid_store->insert( o );
+	}
+}
+
+void nv::root::object_destroyed( object* o )
+{
+	if ( m_lua_state && o->m_lua_index != lua::ref_none )
+	{
+		m_lua_state->unregister_object( o );
+	}
+	if ( m_uid_store && o->m_uid != 0 )
+	{
+		m_uid_store->remove( o->m_uid );
+	}
+}
