bug fixes for indexing and queries