Not such a fan or "results" being a global variable used between everything here.
In javascript functions, anything declared without a "var" is a global... For instance, at least "terms" on the next line can be scoped to just this function.