diff --git a/components/net/sf/briar/transport/OutgoingEncryptionLayer.java b/components/net/sf/briar/transport/OutgoingEncryptionLayer.java
index b801dce9f6f3673fbf8655258f28479ad9790e75..f3cebfd1e9a93bed17503c3507c15e2dab2fc63a 100644
--- a/components/net/sf/briar/transport/OutgoingEncryptionLayer.java
+++ b/components/net/sf/briar/transport/OutgoingEncryptionLayer.java
@@ -32,7 +32,7 @@ class OutgoingEncryptionLayer implements FrameWriter {
 			AuthenticatedCipher frameCipher, ErasableKey tagKey,
 			ErasableKey frameKey, boolean writeTag, int maxFrameLength) {
 		this.out = out;
-		this.capacity = capacity;
+		this.capacity = writeTag ? capacity - TAG_LENGTH : capacity;
 		this.tagCipher = tagCipher;
 		this.frameCipher = frameCipher;
 		this.tagKey = tagKey;
@@ -53,6 +53,9 @@ class OutgoingEncryptionLayer implements FrameWriter {
 			throw new IllegalArgumentException();
 		if(!lastFrame && ciphertextLength < maxFrameLength)
 			throw new IllegalArgumentException();
+		// If the initiator's side of the connection is closed without writing
+		// any payload or padding, don't write a tag or an empty frame
+		if(writeTag && lastFrame && payloadLength + paddingLength == 0) return;
 		// Write the tag if required
 		if(writeTag) {
 			TagEncoder.encodeTag(ciphertext, tagCipher, tagKey);
@@ -63,7 +66,6 @@ class OutgoingEncryptionLayer implements FrameWriter {
 				tagKey.erase();
 				throw e;
 			}
-			capacity -= TAG_LENGTH;
 			writeTag = false;
 		}
 		// Encode the header
@@ -99,6 +101,6 @@ class OutgoingEncryptionLayer implements FrameWriter {
 	}
 
 	public long getRemainingCapacity() {
-		return writeTag ? capacity - TAG_LENGTH : capacity;
+		return capacity;
 	}
 }
\ No newline at end of file
diff --git a/test/net/sf/briar/protocol/simplex/OutgoingSimplexConnectionTest.java b/test/net/sf/briar/protocol/simplex/OutgoingSimplexConnectionTest.java
index a859952e1b82984afbcf0fdd6dcb78665e78c6d0..8706ad15c53ac9e5bba577f928a142b2a53cc408 100644
--- a/test/net/sf/briar/protocol/simplex/OutgoingSimplexConnectionTest.java
+++ b/test/net/sf/briar/protocol/simplex/OutgoingSimplexConnectionTest.java
@@ -131,9 +131,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
 			will(returnValue(null));
 		}});
 		connection.write();
-		// Nothing should have been written except the tag and an empty frame
-		int nothing = TAG_LENGTH + HEADER_LENGTH + MAC_LENGTH;
-		assertEquals(nothing, out.size());
+		// Nothing should have been written
+		assertEquals(0, out.size());
 		// The transport should have been disposed with exception == false
 		assertTrue(transport.getDisposed());
 		assertFalse(transport.getException());
@@ -183,8 +182,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
 		}});
 		connection.write();
 		// Something should have been written
-		int nothing = TAG_LENGTH + HEADER_LENGTH + MAC_LENGTH;
-		assertTrue(out.size() > nothing + UniqueId.LENGTH + message.length);
+		int overhead = TAG_LENGTH + HEADER_LENGTH + MAC_LENGTH;
+		assertTrue(out.size() > overhead + UniqueId.LENGTH + message.length);
 		// The transport should have been disposed with exception == false
 		assertTrue(transport.getDisposed());
 		assertFalse(transport.getException());