Final refactoring, make long-polling works