refactor -- added pubsub.flush
check connection / initiate callback
check connection object / initiate callback
streamline and refactor error handling