fix leaking globals

can we make this `var filter = null;` ?