XHR polling optimization & refactoring.