This block of code has been extracted to sendPublish() method above.