refactor the poll loop to the longPoll function

refactor the poll loop to the longPool function and other refactors