Merged fixes for indexing code from JWAT branch.