Simplify recursive query