Fix a few variables leaking in the global state

`result_vars` and `path__qs` were not declared in their scope and were leaking into the global state.