Index: trunk/nv/gui/gui_element.hh
===================================================================
--- trunk/nv/gui/gui_element.hh	(revision 256)
+++ trunk/nv/gui/gui_element.hh	(revision 257)
@@ -25,18 +25,14 @@
 		class element : public object
 		{
+		protected:
+
+			/**
+			 * Creates a new GUI element with the give root node and postioning data.
+			 *
+			 * @param r The rectangle representing the position and size of this element.
+			 */
+			explicit element( const rectangle& r );
+
 		public:
-
-			/**
-			 * Creates a new GUI element.
-			 */
-			element() : object() {}
-
-			/**
-			 * Creates a new GUI element with the give root node and postioning data.
-			 *
-			 * @param aroot The root object that will be this object's parent.
-			 * @param r The rectangle representing the position and size of this element.
-			 */
-			element( root* aroot, const rectangle& r );
 
 			/**
@@ -49,14 +45,14 @@
 
 			/**
-			 * Event handler for update events.  Calls on_update for all affected children.
+			 * Event handler for update events. 
 			 *
 			 * @param elapsed Time since last update.
 			 */
-			virtual void on_update( uint32 elapsed );
-
-			/**
-			 * Event handler for draw events.  Calls on_draw for all affected children.
-			 */
-			virtual void on_draw();
+			virtual void on_update( uint32 /*elapsed*/ ) {}
+
+			/**
+			 * Event handler for draw events. 
+			 */
+			virtual void on_draw() {}
 
 			/**
@@ -191,4 +187,5 @@
 			virtual void recalculate_absolute_children();
 
+		protected:
 			/**
 			 * Destroys the element.
Index: trunk/nv/gui/gui_environment.hh
===================================================================
--- trunk/nv/gui/gui_environment.hh	(revision 256)
+++ trunk/nv/gui/gui_environment.hh	(revision 257)
@@ -28,5 +28,5 @@
 		{
 		public:
-			screen( root* aroot, const rectangle& r ) : element( aroot, r ) {}
+			screen( const rectangle& r ) : element( r ) {}
 			virtual bool on_event( const io_event& ) { return false; }
 			virtual void recalculate_absolute() { recalculate_absolute_children(); }
@@ -39,4 +39,5 @@
 			// temporary
 			void load_style( const std::string& filename );
+			element* create_element( element* parent, const rectangle& r );
 			void update( element* e, uint32 elapsed );
 			void draw( element* e );
Index: trunk/nv/object.hh
===================================================================
--- trunk/nv/object.hh	(revision 256)
+++ trunk/nv/object.hh	(revision 257)
@@ -30,12 +30,7 @@
 
 		/**
-		 * Object default constructor, needed for RTTI
-		 */
-		object();
-
-		/**
 		 * Object constructor
 		 */
-		object( root* aroot, const string& aid );
+		explicit object( const string& aid );
 
 		/**
@@ -94,9 +89,4 @@
 
 		/**
-		 * Destroys all children.
-		 */
-		void destroy_children();
-
-		/**
 		 * Searches for child by pointer.
 		 *
@@ -133,11 +123,4 @@
 		 */
 		virtual object* get_parent() const { return m_parent; }
-
-		/**
-		 * Returns the root object of this object.
-		 *
-		 * @returns root object of current object
-		 */
-		virtual root* get_root() const { return (root*)m_root; }
 
 		/**
@@ -178,11 +161,8 @@
 		 * Destroys all children, unregisters the object from the uid_store.
 		 */
+	protected:
 		virtual ~object();
 
 	protected:
-		void register_with_lua( const char* lua_name, const char* storage );
-
-	protected:
-		root*   m_root;            ///< pointer to root
 		string  m_id;              ///< id type of the object
 		string  m_name;            ///< name of the object
Index: trunk/nv/root.hh
===================================================================
--- trunk/nv/root.hh	(revision 256)
+++ trunk/nv/root.hh	(revision 257)
@@ -19,18 +19,21 @@
 	{
 	public:
-		root() : object( nullptr, "" ), m_lua_state( nullptr ), m_uid_store( nullptr ) { m_root = this; }
-		virtual void child_added( object* ) {}
-		virtual void child_removed( object* ) {}
-		virtual void object_created( object* o );
-		virtual void object_destroyed( object* o );
+		root() : object( "" ), m_lua_state( nullptr ), m_uid_store( nullptr ) {}
 		lua::state*    get_lua_state()     const { return m_lua_state; }
 		uid_store*     get_uid_store()     const { return m_uid_store; }
-		virtual ~root() 
-		{ 
-			object_destroyed( this );
-			destroy_children(); 
-			m_root = nullptr; 
+		template < typename T >
+		object* create_object( const std::string& id )
+		{
+			object* o = new T(id);
+			object_created(o);
+			return o;
 		}
+		void register_with_lua( object* o, const char* lua_name, const char* storage );
+		void destroy_children( object* o );
+		virtual void destroy_object( object* o );
+		virtual ~root() { destroy_object( this ); }
 	protected:
+		virtual void object_created( object* o );
+
 		lua::state*    m_lua_state;
 		uid_store*     m_uid_store; 
Index: trunk/src/gui/gui_element.cc
===================================================================
--- trunk/src/gui/gui_element.cc	(revision 256)
+++ trunk/src/gui/gui_element.cc	(revision 257)
@@ -7,37 +7,11 @@
 #include "nv/gui/gui_element.hh"
 
-#include "nv/gui/gui_environment.hh"
-
 using namespace nv;
 using namespace nv::gui;
 
-element::element( root* aroot, const rectangle& r ) 
-	: object( aroot, "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr )
+element::element( const rectangle& r ) 
+	: object( "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr )
 {
 
-}
-
-void element::on_update( uint32 elapsed )
-{
-	if ( is_visible() )
-	{
-		for ( object* i : *this )
-		{
-			((element*)i)->on_update( elapsed );
-		}
-	}
-	((environment*)m_root)->update( this, elapsed );
-}
-
-void element::on_draw()
-{
-	if ( is_visible() )
-	{
-		((environment*)m_root)->draw( this );
-		for ( object* i : *this )
-		{
-			((element*)i)->on_draw();
-		}
-	}
 }
 
Index: trunk/src/gui/gui_environment.cc
===================================================================
--- trunk/src/gui/gui_environment.cc	(revision 256)
+++ trunk/src/gui/gui_environment.cc	(revision 257)
@@ -34,5 +34,5 @@
 {
 	m_area.dim( dimension( w->get_width(), w->get_height() ) );
-	m_screen = new screen( this, m_area );
+	m_screen = new screen( m_area );
 	m_renderer = new renderer( w, shader_path );
 	root::add_child( m_screen );
@@ -44,6 +44,23 @@
 }
 
+element* nv::gui::environment::create_element( element* parent, const rectangle& r )
+{
+	element* result = new element( r );
+	object_created( result );
+	if ( parent == nullptr ) parent = m_screen;
+	parent->add_child( result );
+	return result;
+}
+
 void environment::update( element* e, uint32 elapsed )
 {
+	e->on_update( elapsed );
+	if ( e->is_visible() )
+	{
+		for ( object* i : *e )
+		{
+			update( ((element*)i), elapsed );
+		}
+	}
 	if ( e->is_dirty() || e->m_render_data == nullptr )
 	{
@@ -55,15 +72,23 @@
 void environment::draw( element* e )
 {
-	m_renderer->draw( e );
+	if ( e->is_visible() )
+	{
+		e->on_draw();
+		m_renderer->draw( e );
+		for ( object* i : *e )
+		{
+			draw((element*)i);
+		}
+	}
 }
 
 void environment::update()
 {
-	m_screen->on_update( 0 );
+	update( m_screen, 0 );
 }
 
 void environment::draw()
 {
-	m_screen->on_draw();
+	draw( m_screen );
 	m_renderer->draw();
 }
@@ -77,5 +102,5 @@
 environment::~environment()
 {
-	destroy_children();
+	destroy_children( this );
 	delete m_renderer;
 }
Index: trunk/src/object.cc
===================================================================
--- trunk/src/object.cc	(revision 256)
+++ trunk/src/object.cc	(revision 257)
@@ -8,5 +8,4 @@
 
 #include <algorithm>
-#include "nv/root.hh"
 #include "nv/types.hh"
 #include "nv/lua/lua_state.hh"
@@ -15,7 +14,6 @@
 using namespace nv;
 
-object::object()
-	: m_root( nullptr )
-	, m_id()
+object::object( const string& aid )
+	: m_id( aid )
 	, m_name()
 	, m_uid(0)
@@ -26,21 +24,4 @@
 	, m_child_count(0)
 {
-}
-
-object::object( root* aroot, const string& aid )
-	: m_root( aroot )
-	, m_id( aid )
-	, m_name()
-	, m_uid(0)
-	, m_lua_index(lua::ref_none)
-	, m_lua_proto_index(lua::ref_none)
-	, m_parent( nullptr )
-	, m_children()
-	, m_child_count(0)
-{
-	if ( m_root )
-	{
-		m_root->object_created( this );
-	}
 }
 
@@ -56,5 +37,4 @@
 		m_children.push_back( child );
 		m_child_count++;
-		m_root->child_added( child );
 	}
 }
@@ -71,5 +51,4 @@
 		(*it)->m_parent = nullptr;
 		m_children.erase(it);
-		m_root->child_removed( child );
 	}	
 }
@@ -89,20 +68,6 @@
 }
 
-void object::destroy_children()
-{
-	while ( !m_children.empty() )
-	{
-		delete m_children.front();
-	}
-}
-
 object::~object()
 {
-	if ( m_root )
-	{
-		m_root->object_destroyed( this );
-	}
-	detach();
-	destroy_children();
 }
 
@@ -195,18 +160,2 @@
 // 	db->create_type<object>("object").fields(fields);
 // }
-
-void nv::object::register_with_lua( const char* lua_name, const char* storage )
-{
-	lua::state* state = get_root()->get_lua_state();
-	if (state)
-	{
-		if ( lua_name != nullptr )
-		{
-			m_lua_index       = state->register_object( this, lua_name );
-		}
-		if ( storage != nullptr )
-		{
-			m_lua_proto_index = state->register_proto( this, storage );
-		}
-	}
-}
Index: trunk/src/root.cc
===================================================================
--- trunk/src/root.cc	(revision 256)
+++ trunk/src/root.cc	(revision 257)
@@ -18,6 +18,8 @@
 }
 
-void nv::root::object_destroyed( object* o )
+void nv::root::destroy_object( object* o )
 {
+	destroy_children( o );
+	o->detach();
 	if ( m_lua_state && o->m_lua_index != lua::ref_none )
 	{
@@ -28,3 +30,29 @@
 		m_uid_store->remove( o->m_uid );
 	}
+	if ( o != this)	delete o;
 }
+
+void nv::root::destroy_children( object* o )
+{
+	while ( !o->m_children.empty() )
+	{
+		destroy_object( o->m_children.front() );
+	}
+}
+
+void nv::root::register_with_lua( object* o, const char* lua_name, const char* storage )
+{
+	if ( m_lua_state )
+	{
+		if ( lua_name != nullptr )
+		{
+			o->m_lua_index       = m_lua_state->register_object( o, lua_name );
+		}
+		if ( storage != nullptr )
+		{
+			o->m_lua_proto_index = m_lua_state->register_proto( o, storage );
+		}
+	}
+
+}
+
