refactoring and testing pubnub