Recursive query speed improvements