Refactor Ajax polling