Fixed undefined variable query bug.