diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 1336227e5c..5c15aa71c5 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -484,10 +484,10 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
 /*
  * BEGIN callback.
  *
- * Don't send BEGIN message here. Instead, postpone it until the first
+ * Don't send the BEGIN message here instead postpone it until the first
  * change. In logical replication, a common scenario is to replicate a set of
  * tables (instead of all tables) and transactions whose changes were on
- * table(s) that are not published will produce empty transactions. These
+ * the table(s) that are not published will produce empty transactions. These
  * empty transactions will send BEGIN and COMMIT messages to subscribers,
  * using bandwidth on something with little/no use for logical replication.
  */
@@ -538,14 +538,13 @@ pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
 	Assert(txndata);
 
 	/*
-	 * If a BEGIN message was not yet sent, then it means there were no
-	 * relevant changes encountered, so we can skip the COMMIT message
-	 * too.
+	 * We don't need to send the commit message unless some relevant change
+	 * from this transaction has been sent to the downstream.
 	 */
 	sent_begin_txn = txndata->sent_begin_txn;
-	txn->output_plugin_private = NULL;
 	OutputPluginUpdateProgress(ctx, !sent_begin_txn);
 	pfree(txndata);
+	txn->output_plugin_private = NULL;
 
 	if (!sent_begin_txn)
 	{
@@ -562,7 +561,7 @@ pgoutput_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
  * BEGIN PREPARE callback
  */
 static void
-pgoutput_begin_prepare_txn(LogicalDecodingContext * ctx, ReorderBufferTXN * txn)
+pgoutput_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
 {
 	bool		send_replication_origin = txn->origin_id != InvalidRepOriginId;
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 7b4e650212..bba56746c4 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -3581,7 +3581,9 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
  * let nearby code know that we're waiting for that response, to avoid
  * repeated requests.
  *
- * If writePtr is set, mark that as the LSN processed, else use sentPtr.
+ * writePtr is the location up to which the WAL is sent. It is essentially
+ * the same as sentPtr but in some cases, we need to send keep alive before
+ * sentPtr is updated like when skipping empty transactions.
  */
 static void
 WalSndKeepalive(bool requestReply, XLogRecPtr writePtr)
