Query now selects valid ids