refactored xhrReceiver to use mutex and internal state