remove unused global
Simplify by usung r.SetQuery()