Updated query and index builders to use for-comprehensions