First refactoring for long poll query