Reorganize indexing and add unit tests
Merge pull request #1812 from elzj/queue_changes

Issue 4078: Reorganize indexing and add unit tests