Many changes to better handle entity type in indexing