Replaced all code because of serious problems with long polling.