Index: trunk/nv/core/common.hh
===================================================================
--- trunk/nv/core/common.hh	(revision 346)
+++ trunk/nv/core/common.hh	(revision 347)
@@ -196,13 +196,8 @@
 	{
 	protected:
-// 		noncopyable() = default;
-// 		~noncopyable() = default;
-// 		noncopyable( const noncopyable& ) = delete;
-// 		noncopyable& operator=( const noncopyable& ) = delete;
-		noncopyable() {}
-		~noncopyable() {}
-	private:
-		noncopyable( const noncopyable& );
-		noncopyable& operator=( const noncopyable& );
+		noncopyable() = default;
+		~noncopyable() = default;
+		noncopyable( const noncopyable& ) = delete;
+		noncopyable& operator=( const noncopyable& ) = delete;
 	};
 
Index: trunk/nv/core/handle.hh
===================================================================
--- trunk/nv/core/handle.hh	(revision 346)
+++ trunk/nv/core/handle.hh	(revision 347)
@@ -67,21 +67,22 @@
 	};
 
-
-	template < typename HANDLE, typename TINDEX = sint32 >
-	class index_store
-	{
-	public:
+	template < typename HANDLE >
+	class handle_manager
+	{
+		static const sint32 NONE = -1;
+		static const sint32 USED = -2;
+	public:
+
 		typedef HANDLE handle;
-		typedef TINDEX index_type;
 		typedef typename HANDLE::value_type value_type;
 
-		index_store() : m_first_free(-1), m_last_free(-1) {}
-
-		handle create_handle( index_type index )
-		{
-			typedef handle_operator<HANDLE> hop; 
-			value_type i       = get_free_entry();
-			m_entries[i].index = index;
+		handle_manager() : m_first_free( NONE ), m_last_free( NONE ) {}
+
+		handle create_handle()
+		{
+			typedef handle_operator<HANDLE> hop;
+			value_type i = get_free_entry();
 			m_entries[i].counter++;
+			m_entries[i].next_free = USED;
 			return hop::create( i, m_entries[i].counter );
 		}
@@ -89,6 +90,5 @@
 		void free_handle( handle h )
 		{
-			m_entries[ h.index() ].index     = -1;
-			m_entries[ h.index() ].next_free = -1;
+			m_entries[h.index()].next_free = NONE;
 			if ( m_last_free == -1 )
 			{
@@ -96,35 +96,24 @@
 				return;
 			}
-			m_entries[ (unsigned)m_last_free ].next_free = h.index();
+			m_entries[(unsigned)m_last_free].next_free = h.index();
 			m_last_free = h.index();
 		}
 
-		void swap_indices( handle h1, handle h2 )
-		{
-			std::swap( m_entries[ h1.index() ].index, m_entries[ h2.index() ].index );
-		}
-
 		bool is_valid( handle h ) const
 		{
-			typedef handle_operator<HANDLE> hop; 
+			typedef handle_operator<HANDLE> hop;
 			if ( h.is_nil() ) return false;
 			if ( h.index() >= m_entries.size() ) return false;
-			const index_entry& entry = m_entries[ h.index() ];
-			return entry.index >= 0 && entry.counter == hop::get_counter(h);
-		}
-
-		sint32 get_index( handle h ) const
-		{
-			typedef handle_operator<HANDLE> hop; 
-			return m_entries[ h.index() ].counter == hop::get_counter(h) ? m_entries[ h.index() ].index : -1;
-		}
+			const index_entry& entry = m_entries[h.index()];
+			return entry.next_free == USED && entry.counter == hop::get_counter( h );
+		}
+
 	private:
 		struct index_entry
 		{
-			index_type index;
 			value_type counter;
-			index_type next_free;
-
-			index_entry() : index(0), counter(0), next_free(-1) {}
+			sint32     next_free;
+
+			index_entry() : counter( 0 ), next_free( NONE ) {}
 		};
 
@@ -135,5 +124,5 @@
 				value_type result = (value_type)m_first_free;
 				m_first_free = m_entries[result].next_free;
-				m_entries[result].next_free = -1;
+				m_entries[result].next_free = USED;
 				if ( m_first_free == -1 ) m_last_free = -1;
 				return result;
@@ -143,6 +132,6 @@
 		}
 
-		index_type m_first_free;
-		index_type m_last_free;
+		sint32 m_first_free;
+		sint32 m_last_free;
 		std::vector< index_entry > m_entries;
 	};
@@ -188,4 +177,11 @@
 			index_type i = m_indexes[ h.index() ];
 			return i >= 0 ? &(m_data[ (unsigned)i ]) : nullptr;
+		}
+
+		const T* get( handle h ) const
+		{
+			if ( h.is_nil() || h.index() >= m_indexes.size() ) return nullptr;
+			index_type i = m_indexes[h.index()];
+			return i >= 0 ? &( m_data[(unsigned)i] ) : nullptr;
 		}
 
@@ -214,4 +210,6 @@
 		}
 
+		handle get_handle( index_type i ) const { return m_handles[(unsigned)i]; }
+
 		const value_type& operator[] ( index_type i ) const { return m_data[i]; }
 		value_type& operator[] ( index_type i ) { return m_data[i]; }
@@ -245,5 +243,5 @@
 
 	template < typename T, typename HANDLE = handle<>, typename TINDEX = sint32 >
-	class entity_store
+	class handle_store
 	{
 	public:
@@ -257,9 +255,8 @@
 		typedef typename storage::const_reference const_reference;
 
-		entity_store() {}
-
-		explicit entity_store( uint32 reserve )
-		{
-			m_handles.reserve( reserve );
+		handle_store() {}
+
+		explicit handle_store( uint32 reserve )
+		{
 			m_data.reserve( reserve );
 		}
@@ -267,62 +264,48 @@
 		handle create()
 		{
-			m_data.emplace_back();
-			m_handles.push_back( m_indexes.create_handle( sint32( m_data.size() - 1 ) ) );
-			return m_handles.back();
+			handle h = m_indexes.create_handle();
+			m_data.insert( h );
+			return h;
 		}
 
 		bool is_valid( handle h )
 		{
-			return m_indexes.is_valid(h);
+			return m_indexes.is_valid( h );
 		}
 
 		const value_type* get( handle h ) const
 		{
-			if ( h.is_nil() ) return nullptr;
-			sint32 eindex = m_indexes.get_index( h );
-			return eindex >= 0 ? &(m_data[ (unsigned)eindex ]) : nullptr;
+			return m_data.get( h );
 		}
 
 		value_type* get( handle h )
 		{
-			if ( h.is_nil() ) return nullptr;
-			sint32 eindex = m_indexes.get_index( h );
-			return eindex >= 0 ? &(m_data[ (unsigned)eindex ]) : nullptr;
+			return m_data.get( h );
 		}
 
 		void destroy( handle e )
 		{
-			handle swap_handle    = m_handles.back();
-			sint32 dead_eindex    = m_indexes.get_index( e );
-			if ( dead_eindex != (sint32)m_data.size()-1 )
-			{
-				m_data[ (unsigned)dead_eindex ]    = m_data.back();
-				m_handles[ (unsigned)dead_eindex ] = m_handles.back();
-			}
-			m_data.pop_back();
-			m_handles.pop_back();
-			m_indexes.swap_indices( e, swap_handle );
+			m_data.remove( e );
 			m_indexes.free_handle( e );
 		}
 
-		handle get_handle( index_type i ) const { return m_handles[(unsigned)i]; }
+		handle get_handle( index_type i ) const { return m_data.get_handle(i); }
 		const value_type& operator[] ( index_type i ) const { return m_data[(unsigned)i]; }
 		value_type& operator[] ( index_type i ) { return m_data[(unsigned)i]; }
 		size_t size() const { return m_data.size(); }
 
-		iterator        begin()        { return m_data.begin(); }
+		iterator        begin() { return m_data.begin(); }
 		const_iterator  begin()  const { return m_data.cbegin(); }
 		const_iterator  cbegin() const { return m_data.cbegin(); }
 
-		iterator        end()        { return m_data.end(); }
+		iterator        end() { return m_data.end(); }
 		const_iterator  end()  const { return m_data.cend(); }
 		const_iterator  cend() const { return m_data.cend(); }
 
 	private:
-		std::vector< handle >         m_handles;
-		storage                       m_data;
-		index_store< handle, TINDEX > m_indexes;
-	};
-
+		packed_indexed_array< T, handle, TINDEX > m_data;
+		handle_manager< handle >                  m_indexes;
+	};
+	
 }
 
Index: trunk/nv/engine/particle_engine.hh
===================================================================
--- trunk/nv/engine/particle_engine.hh	(revision 346)
+++ trunk/nv/engine/particle_engine.hh	(revision 347)
@@ -190,5 +190,5 @@
 		vec3     m_camera_pos;
 
-		entity_store< particle_system_info, particle_system >      m_systems;
+		handle_store< particle_system_info, particle_system >      m_systems;
 		std::unordered_map< std::string, uint32 >                  m_names;
 		std::vector< particle_system_data >                        m_data; 
Index: trunk/nv/fmod/fmod_audio.hh
===================================================================
--- trunk/nv/fmod/fmod_audio.hh	(revision 346)
+++ trunk/nv/fmod/fmod_audio.hh	(revision 347)
@@ -40,5 +40,5 @@
 			virtual ~audio();
 		private:
-			entity_store< sound_info, sound >     m_sounds;
+			handle_store< sound_info, sound >     m_sounds;
 			vec3                                  m_position;
 			void* m_system;
Index: trunk/nv/gl/gl_context.hh
===================================================================
--- trunk/nv/gl/gl_context.hh	(revision 346)
+++ trunk/nv/gl/gl_context.hh	(revision 347)
@@ -92,6 +92,6 @@
 		void* m_handle;
 
-		entity_store< vertex_array_info, vertex_array >  m_vertex_arrays;
-		entity_store< gl_framebuffer_info, framebuffer > m_framebuffers;
+		handle_store< vertex_array_info, vertex_array >  m_vertex_arrays;
+		handle_store< gl_framebuffer_info, framebuffer > m_framebuffers;
 	};
 
Index: trunk/nv/gl/gl_device.hh
===================================================================
--- trunk/nv/gl/gl_device.hh	(revision 346)
+++ trunk/nv/gl/gl_device.hh	(revision 347)
@@ -67,7 +67,7 @@
 		bool compile( uint32 sh_type, const std::string& shader_code, unsigned& glid );
 		std::string m_shader_header;
-		entity_store< gl_texture_info, texture >         m_textures;
-		entity_store< gl_buffer_info,  buffer >          m_buffers;
-		entity_store< gl_program_info, program >         m_programs;
+		handle_store< gl_texture_info, texture >         m_textures;
+		handle_store< gl_buffer_info,  buffer >          m_buffers;
+		handle_store< gl_program_info, program >         m_programs;
 	};
 
Index: trunk/nv/gui/gui_environment.hh
===================================================================
--- trunk/nv/gui/gui_environment.hh	(revision 346)
+++ trunk/nv/gui/gui_environment.hh	(revision 347)
@@ -58,5 +58,5 @@
 			void recalculate_absolute( handle e );
 			
-			entity_store< element, handle > m_elements;
+			handle_store< element, handle > m_elements;
 			renderer*     m_renderer;
 			window*       m_window;
Index: trunk/nv/sdl/sdl_audio.hh
===================================================================
--- trunk/nv/sdl/sdl_audio.hh	(revision 346)
+++ trunk/nv/sdl/sdl_audio.hh	(revision 347)
@@ -41,5 +41,5 @@
 			vec3                                  m_forward;
 			vec3                                  m_up;
-			entity_store< sound_info, sound >     m_sounds;
+			handle_store< sound_info, sound >     m_sounds;
 		};
 	}
