improved the mem and indexing