From 027ae8340f849064b62e3df93c7a39079f54391e Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Mon, 30 Nov 2015 09:38:25 +0000
Subject: [PATCH] Whitespace-only code formatting changes.

---
 .../android/AndroidExecutorImpl.java          |   6 +-
 .../AndroidNotificationManagerImpl.java       |  34 +-
 .../briarproject/android/BriarActivity.java   |  16 +-
 .../briarproject/android/BriarService.java    |  24 +-
 .../briarproject/android/CrashHandler.java    |   2 +-
 .../android/CrashReportActivity.java          |  92 +--
 .../android/DashboardActivity.java            |  12 +-
 .../briarproject/android/ExpiredActivity.java |   2 +-
 .../android/PasswordActivity.java             |  12 +-
 .../android/ReferenceManagerImpl.java         |  16 +-
 .../android/SettingsActivity.java             |  56 +-
 .../briarproject/android/SetupActivity.java   |  22 +-
 .../android/SplashScreenActivity.java         |  14 +-
 .../briarproject/android/TestingActivity.java | 114 +--
 .../android/contact/ContactListActivity.java  |  54 +-
 .../android/contact/ContactListAdapter.java   |   8 +-
 .../android/contact/ContactListItem.java      |   8 +-
 .../android/contact/ConversationActivity.java |  96 +--
 .../android/contact/ConversationAdapter.java  |  10 +-
 .../contact/ConversationItemComparator.java   |   4 +-
 .../contact/ReadPrivateMessageActivity.java   |  42 +-
 .../android/contact/SelectContactsDialog.java |   6 +-
 .../contact/WritePrivateMessageActivity.java  |  34 +-
 .../groups/AvailableGroupsActivity.java       |  26 +-
 .../groups/AvailableGroupsAdapter.java        |   2 +-
 .../groups/AvailableGroupsItemComparator.java |   2 +-
 .../android/groups/CreateGroupActivity.java   |  14 +-
 .../android/groups/GroupActivity.java         |  80 +-
 .../android/groups/GroupAdapter.java          |   8 +-
 .../android/groups/GroupItemComparator.java   |   4 +-
 .../android/groups/GroupListActivity.java     |  70 +-
 .../android/groups/GroupListAdapter.java      |   6 +-
 .../android/groups/GroupListItem.java         |  10 +-
 .../groups/GroupListItemComparator.java       |   6 +-
 .../android/groups/NoContactsDialog.java      |   2 +-
 .../android/groups/ReadGroupPostActivity.java |  40 +-
 .../android/groups/ShareGroupActivity.java    |  30 +-
 .../groups/WriteGroupPostActivity.java        |  56 +-
 .../identity/CreateIdentityActivity.java      |  12 +-
 .../identity/LocalAuthorItemComparator.java   |  14 +-
 .../identity/LocalAuthorSpinnerAdapter.java   |  18 +-
 .../invitation/AddContactActivity.java        |  84 +-
 .../invitation/ChooseIdentityView.java        |  12 +-
 .../android/invitation/CodeEntryView.java     |   8 +-
 .../android/util/AndroidUtils.java            |   8 +-
 .../briarproject/android/util/AuthorView.java |   2 +-
 .../android/util/StrengthMeter.java           |  10 +-
 .../plugins/droidtooth/DroidtoothPlugin.java  | 138 ++--
 .../DroidtoothTransportConnection.java        |   8 +-
 .../plugins/droidtooth/InsecureBluetooth.java |  50 +-
 .../plugins/tcp/AndroidLanTcpPlugin.java      |   8 +-
 .../briarproject/plugins/tor/TorPlugin.java   | 190 ++---
 .../plugins/tor/TorPluginFactory.java         |  10 +-
 .../plugins/tor/TorTransportConnection.java   |   8 +-
 .../briarproject/system/AndroidFileUtils.java |   4 +-
 .../system/AndroidLocationUtils.java          |   6 +-
 .../system/AndroidSeedProvider.java           |   6 +-
 .../src/org/briarproject/api/Author.java      |   4 +-
 .../src/org/briarproject/api/AuthorId.java    |   2 +-
 briar-api/src/org/briarproject/api/Bytes.java |   4 +-
 .../src/org/briarproject/api/Contact.java     |   2 +-
 .../src/org/briarproject/api/ContactId.java   |   2 +-
 .../src/org/briarproject/api/StringMap.java   |   6 +-
 .../src/org/briarproject/api/TransportId.java |   4 +-
 .../src/org/briarproject/api/UniqueId.java    |   4 +-
 .../briarproject/api/crypto/SecretKey.java    |   2 +-
 .../org/briarproject/api/messaging/Group.java |   6 +-
 .../briarproject/api/messaging/GroupId.java   |   2 +-
 .../briarproject/api/messaging/MessageId.java |   2 +-
 .../api/transport/TemporarySecret.java        |   2 +-
 .../crypto/AuthenticatedCipherImpl.java       |   8 +-
 .../crypto/CombinedSecureRandom.java          |  12 +-
 .../crypto/CryptoComponentImpl.java           |  84 +-
 .../briarproject/crypto/FortunaGenerator.java |  16 +-
 .../crypto/FortunaSecureRandom.java           |   8 +-
 .../org/briarproject/crypto/FrameEncoder.java |  24 +-
 .../crypto/PasswordStrengthEstimatorImpl.java |  18 +-
 .../briarproject/crypto/PseudoRandomImpl.java |   2 +-
 .../briarproject/crypto/Sec1KeyParser.java    |  22 +-
 .../org/briarproject/crypto/Sec1Utils.java    |   4 +-
 .../briarproject/crypto/SignatureImpl.java    |   8 +-
 .../crypto/StreamDecrypterImpl.java           |  26 +-
 .../crypto/StreamEncrypterImpl.java           |  18 +-
 .../src/org/briarproject/data/ReaderImpl.java | 158 ++--
 .../src/org/briarproject/data/WriterImpl.java |  52 +-
 .../briarproject/db/DatabaseCleanerImpl.java  |  14 +-
 .../db/DatabaseComponentImpl.java             | 382 +++++-----
 .../briarproject/db/ExponentialBackoff.java   |  10 +-
 .../src/org/briarproject/db/H2Database.java   |  14 +-
 .../src/org/briarproject/db/JdbcDatabase.java | 716 +++++++++---------
 .../org/briarproject/event/EventBusImpl.java  |   2 +-
 .../invitation/AliceConnector.java            |  50 +-
 .../briarproject/invitation/BobConnector.java |  50 +-
 .../briarproject/invitation/Connector.java    |  64 +-
 .../invitation/ConnectorGroup.java            |  36 +-
 .../lifecycle/LifecycleManagerImpl.java       |  46 +-
 .../lifecycle/ShutdownManagerImpl.java        |   2 +-
 .../messaging/AuthorFactoryImpl.java          |   2 +-
 .../briarproject/messaging/AuthorReader.java  |   2 +-
 .../messaging/CountingConsumer.java           |   4 +-
 .../messaging/DuplexOutgoingSession.java      | 188 ++---
 .../messaging/GroupFactoryImpl.java           |   2 +-
 .../briarproject/messaging/GroupReader.java   |   4 +-
 .../messaging/IncomingSession.java            |  76 +-
 .../messaging/MessageFactoryImpl.java         |  16 +-
 .../briarproject/messaging/MessageImpl.java   |   4 +-
 .../briarproject/messaging/MessageReader.java |  12 +-
 .../messaging/MessageVerifierImpl.java        |   8 +-
 .../messaging/PacketReaderImpl.java           |  94 +--
 .../messaging/PacketWriterImpl.java           |   8 +-
 .../messaging/SimplexOutgoingSession.java     | 120 +--
 .../messaging/SubscriptionUpdateReader.java   |   6 +-
 .../plugins/ConnectionManagerImpl.java        |  98 +--
 .../plugins/ConnectionRegistryImpl.java       |  26 +-
 .../plugins/PluginManagerImpl.java            |  88 +--
 .../org/briarproject/plugins/PollerImpl.java  |   4 +-
 .../briarproject/plugins/file/FilePlugin.java |  22 +-
 .../plugins/file/FileTransportReader.java     |   6 +-
 .../plugins/file/FileTransportWriter.java     |   6 +-
 .../plugins/tcp/LanTcpPlugin.java             |  18 +-
 .../plugins/tcp/PortMapperImpl.java           |  46 +-
 .../briarproject/plugins/tcp/TcpPlugin.java   |  76 +-
 .../plugins/tcp/TcpTransportConnection.java   |   8 +-
 .../plugins/tcp/WanTcpPlugin.java             |  16 +-
 .../src/org/briarproject/reliability/Ack.java |   2 +-
 .../org/briarproject/reliability/Crc32.java   |   8 +-
 .../org/briarproject/reliability/Data.java    |   4 +-
 .../org/briarproject/reliability/Frame.java   |   2 +-
 .../briarproject/reliability/Receiver.java    |  36 +-
 .../reliability/ReceiverInputStream.java      |  12 +-
 .../reliability/ReliabilityLayerImpl.java     |  22 +-
 .../org/briarproject/reliability/Sender.java  |  50 +-
 .../reliability/SenderOutputStream.java       |  12 +-
 .../briarproject/reliability/SlipDecoder.java |  22 +-
 .../briarproject/reliability/SlipEncoder.java |  10 +-
 .../system/LinuxSeedProvider.java             |  10 +-
 .../transport/KeyManagerImpl.java             |  92 +--
 .../transport/ReorderingWindow.java           |  36 +-
 .../transport/StreamReaderImpl.java           |   8 +-
 .../transport/StreamWriterImpl.java           |   4 +-
 .../transport/TagRecogniserImpl.java          |  10 +-
 .../transport/TransportTagRecogniser.java     |  22 +-
 .../src/org/briarproject/util/ByteUtils.java  |  28 +-
 .../briarproject/util/LatchedReference.java   |   4 +-
 .../src/org/briarproject/util/OsUtils.java    |   6 +-
 .../org/briarproject/util/StringUtils.java    |  20 +-
 .../lifecycle/DesktopLifecycleModule.java     |   2 +-
 .../lifecycle/WindowsShutdownManagerImpl.java |  24 +-
 .../plugins/bluetooth/BluetoothPlugin.java    | 106 +--
 .../BluetoothTransportConnection.java         |   8 +-
 .../plugins/bluetooth/InvitationListener.java |  26 +-
 .../file/PollingRemovableDriveMonitor.java    |  12 +-
 .../plugins/file/RemovableDrivePlugin.java    |  28 +-
 .../file/RemovableDrivePluginFactory.java     |   8 +-
 .../file/UnixRemovableDriveFinder.java        |  10 +-
 .../file/UnixRemovableDriveMonitor.java       |  16 +-
 .../file/WindowsRemovableDriveFinder.java     |   8 +-
 .../plugins/modem/CountryCodes.java           |  12 +-
 .../briarproject/plugins/modem/ModemImpl.java | 102 +--
 .../plugins/modem/ModemPlugin.java            |  64 +-
 .../plugins/modem/ModemPluginFactory.java     |   2 +-
 .../plugins/modem/SerialPortImpl.java         |  22 +-
 .../system/DesktopSystemModule.java           |   2 +-
 .../org/briarproject/LockFairnessTest.java    |  14 +-
 .../src/org/briarproject/TestUtils.java       |   4 +-
 .../crypto/EllipticCurvePerformanceTest.java  |  16 +-
 .../crypto/FortunaGeneratorTest.java          |  10 +-
 .../crypto/KeyDerivationTest.java             |  16 +-
 .../crypto/KeyEncodingAndParsingTest.java     |  20 +-
 .../crypto/TestAuthenticatedCipher.java       |   8 +-
 .../org/briarproject/data/ReaderImplTest.java |  32 +-
 .../org/briarproject/data/WriterImplTest.java |   4 +-
 .../src/org/briarproject/db/BasicH2Test.java  |  58 +-
 .../db/DatabaseCleanerImplTest.java           |   2 +-
 .../db/DatabaseComponentTest.java             |  82 +-
 .../org/briarproject/db/H2DatabaseTest.java   |  68 +-
 .../lifecycle/ShutdownManagerImplTest.java    |   6 +-
 .../WindowsShutdownManagerImplTest.java       |   6 +-
 .../briarproject/messaging/ConstantsTest.java |  14 +-
 .../briarproject/messaging/ConsumersTest.java |   2 +-
 .../messaging/PacketReaderImplTest.java       |  24 +-
 .../SimplexMessagingIntegrationTest.java      |   2 +-
 .../plugins/ConnectionRegistryImplTest.java   |   2 +-
 .../plugins/DuplexClientTest.java             |   8 +-
 .../plugins/DuplexServerTest.java             |   8 +-
 .../org/briarproject/plugins/DuplexTest.java  |  16 +-
 .../bluetooth/BluetoothClientTest.java        |   2 +-
 .../PollingRemovableDriveMonitorTest.java     |   4 +-
 .../file/UnixRemovableDriveMonitorTest.java   |   4 +-
 .../plugins/tcp/LanTcpClientTest.java         |   2 +-
 .../plugins/tcp/LanTcpPluginTest.java         |  14 +-
 .../system/LinuxSeedProviderTest.java         |   8 +-
 .../transport/KeyManagerImplTest.java         |  12 +-
 .../transport/KeyRotationIntegrationTest.java |  94 +--
 .../transport/ReorderingWindowTest.java       |  28 +-
 .../transport/StreamWriterImplTest.java       |   2 +-
 .../transport/TestStreamDecrypter.java        |  12 +-
 .../transport/TestStreamEncrypter.java        |   8 +-
 .../transport/TransportIntegrationTest.java   |   4 +-
 .../transport/TransportTagRecogniserTest.java |   6 +-
 .../org/briarproject/util/ByteUtilsTest.java  |   4 +-
 .../briarproject/util/StringUtilsTest.java    |   4 +-
 202 files changed, 2993 insertions(+), 2993 deletions(-)

diff --git a/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java b/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java
index 079df65e2e..1fb060d68e 100644
--- a/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java
+++ b/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java
@@ -42,11 +42,11 @@ class AndroidExecutorImpl implements AndroidExecutor {
 	}
 
 	private void startIfNecessary() {
-		if(started.getAndSet(true)) return;
+		if (started.getAndSet(true)) return;
 		new Thread(loop, "AndroidExecutor").start();
 		try {
 			startLatch.await();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while starting executor thread");
 			Thread.currentThread().interrupt();
 		}
@@ -62,7 +62,7 @@ class AndroidExecutorImpl implements AndroidExecutor {
 	}
 
 	public void shutdown() {
-		if(handler != null) {
+		if (handler != null) {
 			Message m = Message.obtain(handler, SHUTDOWN);
 			handler.sendMessage(m);
 		}
diff --git a/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java b/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java
index a9804413cb..e6207fe1c3 100644
--- a/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java
+++ b/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java
@@ -94,8 +94,8 @@ Service, EventListener {
 			public void run() {
 				try {
 					settings = db.getSettings();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -108,14 +108,14 @@ Service, EventListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof SettingsUpdatedEvent) loadSettings();
+		if (e instanceof SettingsUpdatedEvent) loadSettings();
 	}
 
 	public void showPrivateMessageNotification(ContactId c) {
 		synchLock.lock();
 		try {
 			Integer count = contactCounts.get(c);
-			if(count == null) contactCounts.put(c, 1);
+			if (count == null) contactCounts.put(c, 1);
 			else contactCounts.put(c, count + 1);
 			privateTotal++;
 			updatePrivateMessageNotification();
@@ -128,7 +128,7 @@ Service, EventListener {
 		synchLock.lock();
 		try {
 			Integer count = contactCounts.remove(c);
-			if(count == null) return; // Already cleared
+			if (count == null) return; // Already cleared
 			privateTotal -= count;
 			updatePrivateMessageNotification();
 		} finally {
@@ -138,9 +138,9 @@ Service, EventListener {
 
 	// Locking: synchLock
 	private void updatePrivateMessageNotification() {
-		if(privateTotal == 0) {
+		if (privateTotal == 0) {
 			clearPrivateMessageNotification();
-		} else if(!settings.getBoolean("notifyPrivateMessages", true)) {
+		} else if (!settings.getBoolean("notifyPrivateMessages", true)) {
 			return;
 		} else {
 			NotificationCompat.Builder b =
@@ -152,12 +152,12 @@ Service, EventListener {
 					privateTotal));
 			boolean sound = settings.getBoolean("notifySound", true);
 			String ringtoneUri = settings.get("notifyRingtoneUri");
-			if(sound && !StringUtils.isNullOrEmpty(ringtoneUri))
+			if (sound && !StringUtils.isNullOrEmpty(ringtoneUri))
 				b.setSound(Uri.parse(ringtoneUri));
 			b.setDefaults(getDefaults());
 			b.setOnlyAlertOnce(true);
 			b.setAutoCancel(true);
-			if(contactCounts.size() == 1) {
+			if (contactCounts.size() == 1) {
 				Intent i = new Intent(appContext, ConversationActivity.class);
 				ContactId c = contactCounts.keySet().iterator().next();
 				i.putExtra("briar.CONTACT_ID", c.getInt());
@@ -192,9 +192,9 @@ Service, EventListener {
 		int defaults = DEFAULT_LIGHTS;
 		boolean sound = settings.getBoolean("notifySound", true);
 		String ringtoneUri = settings.get("notifyRingtoneUri");
-		if(sound && StringUtils.isNullOrEmpty(ringtoneUri))
+		if (sound && StringUtils.isNullOrEmpty(ringtoneUri))
 			defaults |= DEFAULT_SOUND;
-		if(settings.getBoolean("notifyVibration", true))
+		if (settings.getBoolean("notifyVibration", true))
 			defaults |= DEFAULT_VIBRATE;
 		return defaults;
 	}
@@ -203,7 +203,7 @@ Service, EventListener {
 		synchLock.lock();
 		try {
 			Integer count = groupCounts.get(g);
-			if(count == null) groupCounts.put(g, 1);
+			if (count == null) groupCounts.put(g, 1);
 			else groupCounts.put(g, count + 1);
 			groupTotal++;
 			updateGroupPostNotification();
@@ -216,7 +216,7 @@ Service, EventListener {
 		synchLock.lock();
 		try {
 			Integer count = groupCounts.remove(g);
-			if(count == null) return; // Already cleared
+			if (count == null) return; // Already cleared
 			groupTotal -= count;
 			updateGroupPostNotification();
 		} finally {
@@ -226,9 +226,9 @@ Service, EventListener {
 
 	// Locking: synchLock
 	private void updateGroupPostNotification() {
-		if(groupTotal == 0) {
+		if (groupTotal == 0) {
 			clearGroupPostNotification();
-		} else if(!settings.getBoolean("notifyGroupPosts", true)) {
+		} else if (!settings.getBoolean("notifyGroupPosts", true)) {
 			return;
 		} else {
 			NotificationCompat.Builder b =
@@ -239,12 +239,12 @@ Service, EventListener {
 					R.plurals.forum_post_notification_text, groupTotal,
 					groupTotal));
 			String ringtoneUri = settings.get("notifyRingtoneUri");
-			if(!StringUtils.isNullOrEmpty(ringtoneUri))
+			if (!StringUtils.isNullOrEmpty(ringtoneUri))
 				b.setSound(Uri.parse(ringtoneUri));
 			b.setDefaults(getDefaults());
 			b.setOnlyAlertOnce(true);
 			b.setAutoCancel(true);
-			if(groupCounts.size() == 1) {
+			if (groupCounts.size() == 1) {
 				Intent i = new Intent(appContext, GroupActivity.class);
 				GroupId g = groupCounts.keySet().iterator().next();
 				i.putExtra("briar.GROUP_ID", g.getBytes());
diff --git a/briar-android/src/org/briarproject/android/BriarActivity.java b/briar-android/src/org/briarproject/android/BriarActivity.java
index eae384e53d..e098bfee7b 100644
--- a/briar-android/src/org/briarproject/android/BriarActivity.java
+++ b/briar-android/src/org/briarproject/android/BriarActivity.java
@@ -45,15 +45,15 @@ public class BriarActivity extends RoboActivity {
 	@Override
 	public void onCreate(Bundle state) {
 		super.onCreate(state);
-		if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
-		if(databaseConfig.getEncryptionKey() != null) startAndBindService();
+		if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
+		if (databaseConfig.getEncryptionKey() != null) startAndBindService();
 	}
 
 	@Override
 	protected void onActivityResult(int request, int result, Intent data) {
 		super.onActivityResult(request, result, data);
-		if(request == REQUEST_PASSWORD) {
-			if(result == RESULT_OK) startAndBindService();
+		if (request == REQUEST_PASSWORD) {
+			if (result == RESULT_OK) startAndBindService();
 			else finish();
 		}
 	}
@@ -61,7 +61,7 @@ public class BriarActivity extends RoboActivity {
 	@Override
 	public void onResume() {
 		super.onResume();
-		if(databaseConfig.getEncryptionKey() == null && !isFinishing()) {
+		if (databaseConfig.getEncryptionKey() == null && !isFinishing()) {
 			Intent i = new Intent(this, PasswordActivity.class);
 			i.setFlags(FLAG_ACTIVITY_NO_ANIMATION | FLAG_ACTIVITY_SINGLE_TOP);
 			startActivityForResult(i, REQUEST_PASSWORD);
@@ -81,7 +81,7 @@ public class BriarActivity extends RoboActivity {
 	}
 
 	private void unbindService() {
-		if(bound) unbindService(serviceConnection);
+		if (bound) unbindService(serviceConnection);
 	}
 
 	protected void signOut() {
@@ -97,7 +97,7 @@ public class BriarActivity extends RoboActivity {
 					LOG.info("Shutting down service");
 					service.shutdown();
 					service.waitForShutdown();
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.warning("Interrupted while waiting for service");
 					Thread.currentThread().interrupt();
 				}
@@ -122,7 +122,7 @@ public class BriarActivity extends RoboActivity {
 				try {
 					lifecycleManager.waitForDatabase();
 					task.run();
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.warning("Interrupted while waiting for database");
 					Thread.currentThread().interrupt();
 				}
diff --git a/briar-android/src/org/briarproject/android/BriarService.java b/briar-android/src/org/briarproject/android/BriarService.java
index ab28acce75..b5e5ea4e54 100644
--- a/briar-android/src/org/briarproject/android/BriarService.java
+++ b/briar-android/src/org/briarproject/android/BriarService.java
@@ -66,12 +66,12 @@ public class BriarService extends RoboService implements EventListener {
 	public void onCreate() {
 		super.onCreate();
 		LOG.info("Created");
-		if(created.getAndSet(true)) {
+		if (created.getAndSet(true)) {
 			LOG.info("Already created");
 			stopSelf();
 			return;
 		}
-		if(databaseConfig.getEncryptionKey() == null) {
+		if (databaseConfig.getEncryptionKey() == null) {
 			LOG.info("No database key");
 			stopSelf();
 			return;
@@ -93,14 +93,14 @@ public class BriarService extends RoboService implements EventListener {
 			@Override
 			public void run() {
 				StartResult result = lifecycleManager.startServices();
-				if(result == SUCCESS) {
+				if (result == SUCCESS) {
 					eventBus.addListener(BriarService.this);
 					started = true;
-				} else if(result == ALREADY_RUNNING) {
+				} else if (result == ALREADY_RUNNING) {
 					LOG.info("Already running");
 					stopSelf();
 				} else {
-					if(LOG.isLoggable(WARNING))
+					if (LOG.isLoggable(WARNING))
 						LOG.warning("Startup failed: " + result);
 					showStartupFailureNotification();
 					stopSelf();
@@ -147,7 +147,7 @@ public class BriarService extends RoboService implements EventListener {
 		new Thread() {
 			@Override
 			public void run() {
-				if(started) {
+				if (started) {
 					eventBus.removeListener(BriarService.this);
 					lifecycleManager.stopServices();
 				}
@@ -164,11 +164,11 @@ public class BriarService extends RoboService implements EventListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof MessageAddedEvent) {
+		if (e instanceof MessageAddedEvent) {
 			MessageAddedEvent m = (MessageAddedEvent) e;
 			GroupId g = m.getGroup().getId();
 			ContactId c = m.getContactId();
-			if(c != null) showMessageNotification(g, c);
+			if (c != null) showMessageNotification(g, c);
 		}
 	}
 
@@ -177,13 +177,13 @@ public class BriarService extends RoboService implements EventListener {
 			public void run() {
 				try {
 					lifecycleManager.waitForDatabase();
-					if(g.equals(db.getInboxGroupId(c)))
+					if (g.equals(db.getInboxGroupId(c)))
 						notificationManager.showPrivateMessageNotification(c);
 					else notificationManager.showGroupPostNotification(g);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.info("Interruped while waiting for database");
 					Thread.currentThread().interrupt();
 				}
diff --git a/briar-android/src/org/briarproject/android/CrashHandler.java b/briar-android/src/org/briarproject/android/CrashHandler.java
index 7eeca47b62..8b2f53c6b3 100644
--- a/briar-android/src/org/briarproject/android/CrashHandler.java
+++ b/briar-android/src/org/briarproject/android/CrashHandler.java
@@ -41,6 +41,6 @@ class CrashHandler implements UncaughtExceptionHandler {
 		i.putExtra("briar.PID", android.os.Process.myPid());
 		ctx.startActivity(i);
 		// Pass the exception to the default handler, if any
-		if(delegate != null) delegate.uncaughtException(thread, throwable);
+		if (delegate != null) delegate.uncaughtException(thread, throwable);
 	}
 }
diff --git a/briar-android/src/org/briarproject/android/CrashReportActivity.java b/briar-android/src/org/briarproject/android/CrashReportActivity.java
index 9a8bc73b6e..539591cb7c 100644
--- a/briar-android/src/org/briarproject/android/CrashReportActivity.java
+++ b/briar-android/src/org/briarproject/android/CrashReportActivity.java
@@ -115,7 +115,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 		progress.setVisibility(GONE);
 		layout.addView(progress);
 
-		if(SHARE_CRASH_REPORTS) {
+		if (SHARE_CRASH_REPORTS) {
 			layout.addView(new HorizontalBorder(this));
 			LinearLayout footer = new LinearLayout(this);
 			footer.setLayoutParams(MATCH_WRAP);
@@ -143,7 +143,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 	@Override
 	public void onDestroy() {
 		super.onDestroy();
-		if(temp != null) temp.delete();
+		if (temp != null) temp.delete();
 	}
 
 	public void onClick(View view) {
@@ -165,7 +165,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 			protected void onPostExecute(Map<String, String> result) {
 				Context ctx = CrashReportActivity.this;
 				int pad = LayoutUtils.getPadding(ctx);
-				for(Entry<String, String> e : result.entrySet()) {
+				for (Entry<String, String> e : result.entrySet()) {
 					TextView title = new TextView(ctx);
 					title.setTextSize(18);
 					title.setText(e.getKey());
@@ -191,9 +191,9 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 		String manufacturer = Build.MANUFACTURER;
 		String model = Build.MODEL;
 		String brand = Build.BRAND;
-		if(model.startsWith(manufacturer)) deviceType = capitalize(model);
+		if (model.startsWith(manufacturer)) deviceType = capitalize(model);
 		else deviceType = capitalize(manufacturer) + " " + model;
-		if(!StringUtils.isNullOrEmpty(brand))
+		if (!StringUtils.isNullOrEmpty(brand))
 			deviceType += " (" + capitalize(brand) + ")";
 		statusMap.put("Device type:", deviceType);
 
@@ -213,7 +213,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 		ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
 		am.getMemoryInfo(mem);
 		String systemMemory;
-		if(Build.VERSION.SDK_INT >= 16) {
+		if (Build.VERSION.SDK_INT >= 16) {
 			systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
 					+ (mem.availMem / 1024 / 1204) + " MiB free, "
 					+ (mem.threshold / 1024 / 1024) + " MiB threshold";
@@ -241,7 +241,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 			String internal = (rootTotal / 1024 / 1024) + " MiB total, "
 					+ (rootFree / 1024 / 1024) + " MiB free";
 			statusMap.put("Internal storage:", internal);
-		} catch(IOException e) {
+		} catch (IOException e) {
 			statusMap.put("Internal storage:", "Unknown");
 		}
 
@@ -253,7 +253,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 			String external = (sdTotal / 1024 / 1024) + " MiB total, "
 					+ (sdFree / 1024 / 1024) + " MiB free";
 			statusMap.put("External storage:", external);
-		} catch(IOException e) {
+		} catch (IOException e) {
 			statusMap.put("External storage:", "Unknown");
 		}
 
@@ -269,26 +269,26 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 			Method method = clazz.getDeclaredMethod("getMobileDataEnabled");
 			method.setAccessible(true);
 			mobileEnabled = (Boolean) method.invoke(cm);
-		} catch(ClassNotFoundException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(NoSuchMethodException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(IllegalAccessException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(IllegalArgumentException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(InvocationTargetException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (ClassNotFoundException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (NoSuchMethodException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IllegalAccessException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IllegalArgumentException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (InvocationTargetException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		// Is mobile data connected ?
 		boolean mobileConnected = mobile != null && mobile.isConnected();
 
 		String mobileStatus;
-		if(mobileAvailable) mobileStatus = "Available, ";
+		if (mobileAvailable) mobileStatus = "Available, ";
 		else mobileStatus = "Not available, ";
-		if(mobileEnabled) mobileStatus += "enabled, ";
+		if (mobileEnabled) mobileStatus += "enabled, ";
 		else mobileStatus += "not enabled, ";
-		if(mobileConnected) mobileStatus += "connected";
+		if (mobileConnected) mobileStatus += "connected";
 		else mobileStatus += "not connected";
 		statusMap.put("Mobile data:", mobileStatus);
 
@@ -303,15 +303,15 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 		boolean wifiConnected = wifi != null && wifi.isConnected();
 
 		String wifiStatus;
-		if(wifiAvailable) wifiStatus = "Available, ";
+		if (wifiAvailable) wifiStatus = "Available, ";
 		else wifiStatus = "Not available, ";
-		if(wifiEnabled) wifiStatus += "enabled, ";
+		if (wifiEnabled) wifiStatus += "enabled, ";
 		else wifiStatus += "not enabled, ";
-		if(wifiConnected) wifiStatus += "connected";
+		if (wifiConnected) wifiStatus += "connected";
 		else wifiStatus += "not connected";
-		if(wm != null) {
+		if (wm != null) {
 			WifiInfo wifiInfo = wm.getConnectionInfo();
-			if(wifiInfo != null) {
+			if (wifiInfo != null) {
 				int ip = wifiInfo.getIpAddress(); // Nice API, Google
 				int ip1 = ip & 0xFF;
 				int ip2 = (ip >> 8) & 0xFF;
@@ -331,11 +331,11 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 					return BluetoothAdapter.getDefaultAdapter();
 				}
 			});
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while getting BluetoothAdapter");
 			Thread.currentThread().interrupt();
-		} catch(ExecutionException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (ExecutionException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		boolean btAvailable = bt != null;
 		// Is Bluetooth enabled?
@@ -350,37 +350,37 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 				bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
 
 		String btStatus;
-		if(btAvailable) btStatus = "Available, ";
+		if (btAvailable) btStatus = "Available, ";
 		else btStatus = "Not available, ";
-		if(btEnabled) btStatus += "enabled, ";
+		if (btEnabled) btStatus += "enabled, ";
 		else btStatus += "not enabled, ";
-		if(btConnectable) btStatus += "connectable, ";
+		if (btConnectable) btStatus += "connectable, ";
 		else btStatus += "not connectable, ";
-		if(btDiscoverable) btStatus += "discoverable";
+		if (btDiscoverable) btStatus += "discoverable";
 		else btStatus += "not discoverable";
-		if(bt != null) btStatus += "\nAddress: " + bt.getAddress();
+		if (bt != null) btStatus += "\nAddress: " + bt.getAddress();
 		statusMap.put("Bluetooth:", btStatus);
 
 		// Stack trace
-		if(stack != null) statusMap.put("Stack trace:", stack);
+		if (stack != null) statusMap.put("Stack trace:", stack);
 
 		// All log output from the crashed process
-		if(pid != -1) {
+		if (pid != -1) {
 			StringBuilder log = new StringBuilder();
 			try {
 				Pattern pattern = Pattern.compile(".*\\( *" + pid + "\\).*");
 				Process process = runtime.exec("logcat -d -v time *:I");
 				Scanner scanner = new Scanner(process.getInputStream());
-				while(scanner.hasNextLine()) {
+				while (scanner.hasNextLine()) {
 					String line = scanner.nextLine();
-					if(pattern.matcher(line).matches()) {
+					if (pattern.matcher(line).matches()) {
 						log.append(line);
 						log.append('\n');
 					}
 				}
 				scanner.close();
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 			statusMap.put("Debugging log:", log.toString());
 		}
@@ -389,9 +389,9 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 	}
 
 	private String capitalize(String s) {
-		if(StringUtils.isNullOrEmpty(s)) return s;
+		if (StringUtils.isNullOrEmpty(s)) return s;
 		char first = s.charAt(0);
-		if(Character.isUpperCase(first)) return s;
+		if (Character.isUpperCase(first)) return s;
 		return Character.toUpperCase(first) + s.substring(1);
 	}
 
@@ -408,10 +408,10 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 				try {
 					File shared = Environment.getExternalStorageDirectory();
 					temp = File.createTempFile("crash", ".txt", shared);
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Writing to " + temp.getPath());
 					PrintStream p = new PrintStream(new FileOutputStream(temp));
-					for(Entry<String, String> e : result.entrySet()) {
+					for (Entry<String, String> e : result.entrySet()) {
 						p.println(e.getKey());
 						p.println(e.getValue());
 						p.println();
@@ -419,8 +419,8 @@ public class CrashReportActivity extends Activity implements OnClickListener {
 					p.flush();
 					p.close();
 					sendEmail(Uri.fromFile(temp));
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/DashboardActivity.java b/briar-android/src/org/briarproject/android/DashboardActivity.java
index d340a6d8ec..8e261318a2 100644
--- a/briar-android/src/org/briarproject/android/DashboardActivity.java
+++ b/briar-android/src/org/briarproject/android/DashboardActivity.java
@@ -59,11 +59,11 @@ public class DashboardActivity extends BriarActivity {
 	private void handleIntent(Intent i) {
 		boolean failed = i.getBooleanExtra("briar.STARTUP_FAILED", false);
 		long handle = i.getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1);
-		if(failed) {
+		if (failed) {
 			finish();
 			LOG.info("Exiting");
 			System.exit(0);
-		} else if(handle == -1) {
+		} else if (handle == -1) {
 			// The activity has been launched before
 			showButtons();
 		} else {
@@ -72,7 +72,7 @@ public class DashboardActivity extends BriarActivity {
 					LocalAuthor.class);
 			// The reference may be null if the activity has been recreated,
 			// for example due to screen rotation
-			if(a == null) {
+			if (a == null) {
 				showButtons();
 			} else {
 				showSpinner();
@@ -192,15 +192,15 @@ public class DashboardActivity extends BriarActivity {
 					long now = System.currentTimeMillis();
 					db.addLocalAuthor(a);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Storing author took " + duration + " ms");
 					runOnUiThread(new Runnable() {
 						public void run() {
 							showButtons();
 						}
 					});
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/ExpiredActivity.java b/briar-android/src/org/briarproject/android/ExpiredActivity.java
index d61f22646b..84807661dd 100644
--- a/briar-android/src/org/briarproject/android/ExpiredActivity.java
+++ b/briar-android/src/org/briarproject/android/ExpiredActivity.java
@@ -19,7 +19,7 @@ public class ExpiredActivity extends Activity {
 	public void onCreate(Bundle state) {
 		super.onCreate(state);
 
-		if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
+		if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
 
 		LinearLayout layout = new LinearLayout(this);
 		layout.setLayoutParams(MATCH_MATCH);
diff --git a/briar-android/src/org/briarproject/android/PasswordActivity.java b/briar-android/src/org/briarproject/android/PasswordActivity.java
index 17173a4f61..8981670187 100644
--- a/briar-android/src/org/briarproject/android/PasswordActivity.java
+++ b/briar-android/src/org/briarproject/android/PasswordActivity.java
@@ -58,11 +58,11 @@ public class PasswordActivity extends RoboActivity {
 	public void onCreate(Bundle state) {
 		super.onCreate(state);
 
-		if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
+		if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
 
 		SharedPreferences prefs = getSharedPreferences("db", MODE_PRIVATE);
 		String hex = prefs.getString("key", null);
-		if(hex == null || !databaseConfig.databaseExists()) {
+		if (hex == null || !databaseConfig.databaseExists()) {
 			// Storage has been deleted - clean up and return to setup
 			prefs.edit().clear().commit();
 			delete(databaseConfig.getDatabaseDirectory());
@@ -121,12 +121,12 @@ public class PasswordActivity extends RoboActivity {
 	}
 
 	private void delete(File f) {
-		if(f.isFile()) f.delete();
-		else if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
+		if (f.isFile()) f.delete();
+		else if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
 	}
 
 	private void validatePassword(final byte[] encrypted, Editable e) {
-		if(progress == null) return; // Not created yet
+		if (progress == null) return; // Not created yet
 		// Hide the soft keyboard
 		Object o = getSystemService(INPUT_METHOD_SERVICE);
 		((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
@@ -138,7 +138,7 @@ public class PasswordActivity extends RoboActivity {
 		cryptoExecutor.execute(new Runnable() {
 			public void run() {
 				byte[] key = crypto.decryptWithPassword(encrypted, password);
-				if(key == null) {
+				if (key == null) {
 					tryAgain();
 				} else {
 					databaseConfig.setEncryptionKey(new SecretKey(key));
diff --git a/briar-android/src/org/briarproject/android/ReferenceManagerImpl.java b/briar-android/src/org/briarproject/android/ReferenceManagerImpl.java
index b7b764f097..9844648b72 100644
--- a/briar-android/src/org/briarproject/android/ReferenceManagerImpl.java
+++ b/briar-android/src/org/briarproject/android/ReferenceManagerImpl.java
@@ -26,12 +26,12 @@ class ReferenceManagerImpl implements ReferenceManager {
 		synchLock.lock();
 		try {
 			Map<Long, Object> innerMap = outerMap.get(c);
-			if(innerMap == null) {
-				if(LOG.isLoggable(INFO))
+			if (innerMap == null) {
+				if (LOG.isLoggable(INFO))
 					LOG.info("0 handles for " + c.getName());
 				return null;
 			}
-			if(LOG.isLoggable(INFO))
+			if (LOG.isLoggable(INFO))
 				LOG.info(innerMap.size() + " handles for " + c.getName());
 			Object o = innerMap.get(handle);
 			return c.cast(o);
@@ -45,13 +45,13 @@ class ReferenceManagerImpl implements ReferenceManager {
 		synchLock.lock();
 		try {
 			Map<Long, Object> innerMap = outerMap.get(c);
-			if(innerMap == null) {
+			if (innerMap == null) {
 				innerMap = new HashMap<Long, Object>();
 				outerMap.put(c, innerMap);
 			}
 			long handle = nextHandle++;
 			innerMap.put(handle, reference);
-			if(LOG.isLoggable(INFO)) {
+			if (LOG.isLoggable(INFO)) {
 				LOG.info(innerMap.size() + " handles for " + c.getName() +
 						" after put");
 			}
@@ -65,10 +65,10 @@ class ReferenceManagerImpl implements ReferenceManager {
 		synchLock.lock();
 		try {
 			Map<Long, Object> innerMap = outerMap.get(c);
-			if(innerMap == null) return null;
+			if (innerMap == null) return null;
 			Object o = innerMap.remove(handle);
-			if(innerMap.isEmpty()) outerMap.remove(c);
-			if(LOG.isLoggable(INFO)) {
+			if (innerMap.isEmpty()) outerMap.remove(c);
+			if (LOG.isLoggable(INFO)) {
 				LOG.info(innerMap.size() + " handles for " + c.getName() +
 						" after remove");
 			}
diff --git a/briar-android/src/org/briarproject/android/SettingsActivity.java b/briar-android/src/org/briarproject/android/SettingsActivity.java
index 088f7b4464..a01391602e 100644
--- a/briar-android/src/org/briarproject/android/SettingsActivity.java
+++ b/briar-android/src/org/briarproject/android/SettingsActivity.java
@@ -183,7 +183,7 @@ OnClickListener {
 
 		layout.addView(new HorizontalBorder(this));
 
-		if(SHOW_TESTING_ACTIVITY) {
+		if (SHOW_TESTING_ACTIVITY) {
 			LinearLayout footer = new LinearLayout(this);
 			footer.setLayoutParams(MATCH_WRAP);
 			footer.setGravity(CENTER);
@@ -215,12 +215,12 @@ OnClickListener {
 					TransportConfig c = db.getConfig(new TransportId("bt"));
 					settings = db.getSettings();
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading settings took " + duration + " ms");
 					bluetoothSetting = c.getBoolean("enable", true);
 					displaySettings();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -234,7 +234,7 @@ OnClickListener {
 				progress.setVisibility(GONE);
 
 				int resId;
-				if(bluetoothSetting) resId = R.string.bluetooth_setting_enabled;
+				if (bluetoothSetting) resId = R.string.bluetooth_setting_enabled;
 				else resId = R.string.bluetooth_setting_disabled;
 				enableBluetoothHint.setText(resId);
 
@@ -248,9 +248,9 @@ OnClickListener {
 						"notifyVibration", true));
 
 				String text;
-				if(settings.getBoolean("notifySound", true)) {
+				if (settings.getBoolean("notifySound", true)) {
 					String ringtoneName = settings.get("notifyRingtoneName");
-					if(StringUtils.isNullOrEmpty(ringtoneName))
+					if (StringUtils.isNullOrEmpty(ringtoneName))
 						text = getString(R.string.notify_sound_setting_default);
 					else text = ringtoneName;
 				} else {
@@ -268,43 +268,43 @@ OnClickListener {
 	}
 
 	public void onClick(View view) {
-		if(progress == null) return; // Not created yet
-		if(view == testingButton) {
+		if (progress == null) return; // Not created yet
+		if (view == testingButton) {
 			startActivity(new Intent(this, TestingActivity.class));
-		} else if(view == enableBluetooth || view == enableBluetoothHint) {
+		} else if (view == enableBluetooth || view == enableBluetoothHint) {
 			bluetoothSetting = !bluetoothSetting;
 			BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-			if(adapter != null) {
-				if(bluetoothSetting) adapter.enable();
+			if (adapter != null) {
+				if (bluetoothSetting) adapter.enable();
 				else adapter.disable();
 			}
 			storeBluetoothSetting();
 			displaySettings();
 			return;
-		} else if(view == notifyPrivateMessages) {
+		} else if (view == notifyPrivateMessages) {
 			Settings s = new Settings();
 			s.putBoolean("notifyPrivateMessages",
 					notifyPrivateMessages.isChecked());
 			storeSettings(s);
-		} else if(view == notifyGroupPosts) {
+		} else if (view == notifyGroupPosts) {
 			Settings s = new Settings();
 			s.putBoolean("notifyGroupPosts", notifyGroupPosts.isChecked());
 			storeSettings(s);
-		} else if(view == notifyVibration) {
+		} else if (view == notifyVibration) {
 			Settings s = new Settings();
 			s.putBoolean("notifyVibration", notifyVibration.isChecked());
 			storeSettings(s);
-		} else if(view == notifySound || view == notifySoundHint) {
+		} else if (view == notifySound || view == notifySoundHint) {
 			String title = getString(R.string.choose_ringtone_title);
 			Intent i = new Intent(ACTION_RINGTONE_PICKER);
 			i.putExtra(EXTRA_RINGTONE_TYPE, TYPE_NOTIFICATION);
 			i.putExtra(EXTRA_RINGTONE_TITLE, title);
 			i.putExtra(EXTRA_RINGTONE_DEFAULT_URI, DEFAULT_NOTIFICATION_URI);
 			i.putExtra(EXTRA_RINGTONE_SHOW_SILENT, true);
-			if(settings.getBoolean("notifySound", true)) {
+			if (settings.getBoolean("notifySound", true)) {
 				Uri uri;
 				String ringtoneUri = settings.get("notifyRingtoneUri");
-				if(StringUtils.isNullOrEmpty(ringtoneUri))
+				if (StringUtils.isNullOrEmpty(ringtoneUri))
 					uri = DEFAULT_NOTIFICATION_URI;
 				else uri = Uri.parse(ringtoneUri);
 				i.putExtra(EXTRA_RINGTONE_EXISTING_URI, uri);
@@ -322,10 +322,10 @@ OnClickListener {
 					long now = System.currentTimeMillis();
 					db.mergeConfig(new TransportId("bt"), c);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Merging config took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -339,10 +339,10 @@ OnClickListener {
 					long now = System.currentTimeMillis();
 					db.mergeSettings(settings);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Merging settings took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -352,16 +352,16 @@ OnClickListener {
 	@Override
 	public void onActivityResult(int request, int result, Intent data) {
 		super.onActivityResult(request, result, data);
-		if(request == REQUEST_RINGTONE && result == RESULT_OK) {
+		if (request == REQUEST_RINGTONE && result == RESULT_OK) {
 			Settings s = new Settings();
 			Uri uri = data.getParcelableExtra(EXTRA_RINGTONE_PICKED_URI);
-			if(uri == null) {
+			if (uri == null) {
 				// The user chose silence
 				notifySoundHint.setText(R.string.notify_sound_setting_disabled);
 				s.putBoolean("notifySound", false);
 				s.put("notifyRingtoneName", "");
 				s.put("notifyRingtoneUri", "");
-			} else if(RingtoneManager.isDefault(uri)) {
+			} else if (RingtoneManager.isDefault(uri)) {
 				// The user chose the default
 				notifySoundHint.setText(R.string.notify_sound_setting_default);
 				s.putBoolean("notifySound", true);
@@ -381,7 +381,7 @@ OnClickListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof SettingsUpdatedEvent) {
+		if (e instanceof SettingsUpdatedEvent) {
 			LOG.info("Settings updated");
 			loadSettings();
 		}
diff --git a/briar-android/src/org/briarproject/android/SetupActivity.java b/briar-android/src/org/briarproject/android/SetupActivity.java
index 7d05038ed6..5c6f11a955 100644
--- a/briar-android/src/org/briarproject/android/SetupActivity.java
+++ b/briar-android/src/org/briarproject/android/SetupActivity.java
@@ -80,7 +80,7 @@ OnEditorActionListener {
 	public void onCreate(Bundle state) {
 		super.onCreate(state);
 
-		if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
+		if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
 
 		LinearLayout layout = new LinearLayout(this);
 		layout.setLayoutParams(MATCH_MATCH);
@@ -181,8 +181,8 @@ OnEditorActionListener {
 	}
 
 	private void enableOrDisableContinueButton() {
-		if(progress == null) return; // Not created yet
-		if(passwordEntry.getText().length() > 0)
+		if (progress == null) return; // Not created yet
+		if (passwordEntry.getText().length() > 0)
 			strengthMeter.setVisibility(VISIBLE);
 		else strengthMeter.setVisibility(INVISIBLE);
 		String nickname = nicknameEntry.getText().toString();
@@ -192,15 +192,15 @@ OnEditorActionListener {
 		boolean passwordsMatch = firstPassword.equals(secondPassword);
 		float strength = strengthEstimator.estimateStrength(firstPassword);
 		strengthMeter.setStrength(strength);
-		if(nicknameLength > MAX_AUTHOR_NAME_LENGTH) {
+		if (nicknameLength > MAX_AUTHOR_NAME_LENGTH) {
 			feedback.setText(R.string.name_too_long);
-		} else if(firstPassword.length() == 0) {
+		} else if (firstPassword.length() == 0) {
 			feedback.setText("");
-		} else if(secondPassword.length() == 0 || passwordsMatch) {
-			if(strength < PasswordStrengthEstimator.WEAK)
+		} else if (secondPassword.length() == 0 || passwordsMatch) {
+			if (strength < PasswordStrengthEstimator.WEAK)
 				feedback.setText(R.string.password_too_weak);
 			else feedback.setText("");
-		} else if(!passwordsMatch) {
+		} else if (!passwordsMatch) {
 			feedback.setText(R.string.passwords_do_not_match);
 		} else {
 			feedback.setText("");
@@ -245,7 +245,7 @@ OnEditorActionListener {
 		editor.putString("key", StringUtils.toHexString(encrypted));
 		editor.commit();
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Key storage took " + duration + " ms");
 	}
 
@@ -253,7 +253,7 @@ OnEditorActionListener {
 		long now = System.currentTimeMillis();
 		byte[] encrypted = crypto.encryptWithPassword(key.getBytes(), password);
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Key derivation took " + duration + " ms");
 		return encrypted;
 	}
@@ -266,7 +266,7 @@ OnEditorActionListener {
 		LocalAuthor localAuthor = authorFactory.createLocalAuthor(nickname,
 				publicKey, privateKey);
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Identity creation took " + duration + " ms");
 		return localAuthor;
 	}
diff --git a/briar-android/src/org/briarproject/android/SplashScreenActivity.java b/briar-android/src/org/briarproject/android/SplashScreenActivity.java
index 0cccbc4cd2..319771e83d 100644
--- a/briar-android/src/org/briarproject/android/SplashScreenActivity.java
+++ b/briar-android/src/org/briarproject/android/SplashScreenActivity.java
@@ -51,7 +51,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
 	public void onCreate(Bundle state) {
 		super.onCreate(state);
 
-		if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
+		if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
 
 		LinearLayout layout = new LinearLayout(this);
 		layout.setLayoutParams(MATCH_MATCH);
@@ -71,9 +71,9 @@ public class SplashScreenActivity extends RoboSplashActivity {
 	@Override
 	protected void startNextActivity() {
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Guice startup took " + duration + " ms");
-		if(System.currentTimeMillis() >= EXPIRY_DATE) {
+		if (System.currentTimeMillis() >= EXPIRY_DATE) {
 			LOG.info("Expired");
 			startActivity(new Intent(this, ExpiredActivity.class));
 		} else {
@@ -81,7 +81,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
 			String hex = prefs.getString("key", null);
 			Injector i = RoboGuice.getBaseApplicationInjector(getApplication());
 			DatabaseConfig databaseConfig = i.getInstance(DatabaseConfig.class);
-			if(hex != null && databaseConfig.databaseExists()) {
+			if (hex != null && databaseConfig.databaseExists()) {
 				startActivity(new Intent(this, DashboardActivity.class));
 			} else {
 				prefs.edit().clear().commit();
@@ -93,7 +93,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
 
 	@SuppressLint("NewApi")
 	private void enableStrictMode() {
-		if(TESTING && Build.VERSION.SDK_INT >= 9) {
+		if (TESTING && Build.VERSION.SDK_INT >= 9) {
 			ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
 			threadPolicy.detectAll();
 			threadPolicy.penaltyLog();
@@ -106,7 +106,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
 	}
 
 	private void delete(File f) {
-		if(f.isFile()) f.delete();
-		else if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
+		if (f.isFile()) f.delete();
+		else if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
 	}
 }
diff --git a/briar-android/src/org/briarproject/android/TestingActivity.java b/briar-android/src/org/briarproject/android/TestingActivity.java
index 72ef2ab63b..16541e68fa 100644
--- a/briar-android/src/org/briarproject/android/TestingActivity.java
+++ b/briar-android/src/org/briarproject/android/TestingActivity.java
@@ -153,12 +153,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 	@Override
 	public void onDestroy() {
 		super.onDestroy();
-		if(temp != null) temp.delete();
+		if (temp != null) temp.delete();
 	}
 
 	public void onClick(View view) {
-		if(view == refresh) refresh();
-		else if(view == share) share();
+		if (view == refresh) refresh();
+		else if (view == share) share();
 	}
 
 	private void refresh() {
@@ -175,7 +175,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 			@Override
 			protected void onPostExecute(Map<String, String> result) {
 				int pad = LayoutUtils.getPadding(TestingActivity.this);
-				for(Entry<String, String> e : result.entrySet()) {
+				for (Entry<String, String> e : result.entrySet()) {
 					TextView title = new TextView(TestingActivity.this);
 					title.setTextSize(18);
 					title.setText(e.getKey());
@@ -202,9 +202,9 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 		String manufacturer = Build.MANUFACTURER;
 		String model = Build.MODEL;
 		String brand = Build.BRAND;
-		if(model.startsWith(manufacturer)) deviceType = capitalize(model);
+		if (model.startsWith(manufacturer)) deviceType = capitalize(model);
 		else deviceType = capitalize(manufacturer) + " " + model;
-		if(!StringUtils.isNullOrEmpty(brand))
+		if (!StringUtils.isNullOrEmpty(brand))
 			deviceType += " (" + capitalize(brand) + ")";
 		statusMap.put("Device type:", deviceType);
 
@@ -224,7 +224,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 		ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
 		am.getMemoryInfo(mem);
 		String systemMemory;
-		if(Build.VERSION.SDK_INT >= 16) {
+		if (Build.VERSION.SDK_INT >= 16) {
 			systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
 					+ (mem.availMem / 1024 / 1204) + " MiB free, "
 					+ (mem.threshold / 1024 / 1024) + " MiB threshold";
@@ -252,7 +252,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 			String internal = (rootTotal / 1024 / 1024) + " MiB total, "
 					+ (rootFree / 1024 / 1024) + " MiB free";
 			statusMap.put("Internal storage:", internal);
-		} catch(IOException e) {
+		} catch (IOException e) {
 			statusMap.put("Internal storage:", "Unknown");
 		}
 
@@ -264,7 +264,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 			String external = (sdTotal / 1024 / 1024) + " MiB total, "
 					+ (sdFree / 1024 / 1024) + " MiB free";
 			statusMap.put("External storage:", external);
-		} catch(IOException e) {
+		} catch (IOException e) {
 			statusMap.put("External storage:", "Unknown");
 		}
 
@@ -280,26 +280,26 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 			Method method = clazz.getDeclaredMethod("getMobileDataEnabled");
 			method.setAccessible(true);
 			mobileEnabled = (Boolean) method.invoke(cm);
-		} catch(ClassNotFoundException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(NoSuchMethodException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(IllegalAccessException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(IllegalArgumentException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(InvocationTargetException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (ClassNotFoundException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (NoSuchMethodException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IllegalAccessException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IllegalArgumentException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (InvocationTargetException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		// Is mobile data connected ?
 		boolean mobileConnected = mobile != null && mobile.isConnected();
 
 		String mobileStatus;
-		if(mobileAvailable) mobileStatus = "Available, ";
+		if (mobileAvailable) mobileStatus = "Available, ";
 		else mobileStatus = "Not available, ";
-		if(mobileEnabled) mobileStatus += "enabled, ";
+		if (mobileEnabled) mobileStatus += "enabled, ";
 		else mobileStatus += "not enabled, ";
-		if(mobileConnected) mobileStatus += "connected";
+		if (mobileConnected) mobileStatus += "connected";
 		else mobileStatus += "not connected";
 		statusMap.put("Mobile data:", mobileStatus);
 
@@ -314,15 +314,15 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 		boolean wifiConnected = wifi != null && wifi.isConnected();
 
 		String wifiStatus;
-		if(wifiAvailable) wifiStatus = "Available, ";
+		if (wifiAvailable) wifiStatus = "Available, ";
 		else wifiStatus = "Not available, ";
-		if(wifiEnabled) wifiStatus += "enabled, ";
+		if (wifiEnabled) wifiStatus += "enabled, ";
 		else wifiStatus += "not enabled, ";
-		if(wifiConnected) wifiStatus += "connected";
+		if (wifiConnected) wifiStatus += "connected";
 		else wifiStatus += "not connected";
-		if(wm != null) {
+		if (wm != null) {
 			WifiInfo wifiInfo = wm.getConnectionInfo();
-			if(wifiInfo != null) {
+			if (wifiInfo != null) {
 				int ip = wifiInfo.getIpAddress(); // Nice API, Google
 				int ip1 = ip & 0xFF;
 				int ip2 = (ip >> 8) & 0xFF;
@@ -342,11 +342,11 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 					return BluetoothAdapter.getDefaultAdapter();
 				}
 			});
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while getting BluetoothAdapter");
 			Thread.currentThread().interrupt();
-		} catch(ExecutionException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (ExecutionException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		boolean btAvailable = bt != null;
 		// Is Bluetooth enabled?
@@ -361,26 +361,26 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 				bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
 
 		String btStatus;
-		if(btAvailable) btStatus = "Available, ";
+		if (btAvailable) btStatus = "Available, ";
 		else btStatus = "Not available, ";
-		if(btEnabled) btStatus += "enabled, ";
+		if (btEnabled) btStatus += "enabled, ";
 		else btStatus += "not enabled, ";
-		if(btConnectable) btStatus += "connectable, ";
+		if (btConnectable) btStatus += "connectable, ";
 		else btStatus += "not connectable, ";
-		if(btDiscoverable) btStatus += "discoverable";
+		if (btDiscoverable) btStatus += "discoverable";
 		else btStatus += "not discoverable";
-		if(bt != null) btStatus += "\nAddress: " + bt.getAddress();
+		if (bt != null) btStatus += "\nAddress: " + bt.getAddress();
 		statusMap.put("Bluetooth:", btStatus);
 
 		Map<TransportId, TransportProperties> props = Collections.emptyMap();
 		try {
 			lifecycleManager.waitForDatabase();
 			props = db.getLocalProperties();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.info("Interrupted while waiting for database");
 			Thread.currentThread().interrupt();
-		} catch(DbException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (DbException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 
 		Plugin torPlugin = pluginManager.getPlugin(new TransportId("tor"));
@@ -388,12 +388,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 		boolean torPluginRunning = torPlugin != null && torPlugin.isRunning();
 
 		String torPluginStatus;
-		if(torPluginEnabled) torPluginStatus = "Enabled, ";
+		if (torPluginEnabled) torPluginStatus = "Enabled, ";
 		else torPluginStatus = "Not enabled, ";
-		if(torPluginRunning) torPluginStatus += "running";
+		if (torPluginRunning) torPluginStatus += "running";
 		else torPluginStatus += "not running";
 		TransportProperties torProps = props.get(new TransportId("tor"));
-		if(torProps != null)
+		if (torProps != null)
 			torPluginStatus += "\nAddress: " + torProps.get("onion");
 		statusMap.put("Tor plugin:", torPluginStatus);
 
@@ -402,12 +402,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 		boolean lanPluginRunning = lanPlugin != null && lanPlugin.isRunning();
 
 		String lanPluginStatus;
-		if(lanPluginEnabled) lanPluginStatus = "Enabled, ";
+		if (lanPluginEnabled) lanPluginStatus = "Enabled, ";
 		else lanPluginStatus = "Not enabled, ";
-		if(lanPluginRunning) lanPluginStatus += "running";
+		if (lanPluginRunning) lanPluginStatus += "running";
 		else lanPluginStatus += "not running";
 		TransportProperties lanProps = props.get(new TransportId("lan"));
-		if(lanProps != null)
+		if (lanProps != null)
 			lanPluginStatus += "\nAddress: " + lanProps.get("address");
 		statusMap.put("LAN plugin:", lanPluginStatus);
 
@@ -416,12 +416,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 		boolean btPluginRunning = btPlugin != null && btPlugin.isRunning();
 
 		String btPluginStatus;
-		if(btPluginEnabled) btPluginStatus = "Enabled, ";
+		if (btPluginEnabled) btPluginStatus = "Enabled, ";
 		else btPluginStatus = "Not enabled, ";
-		if(btPluginRunning) btPluginStatus += "running";
+		if (btPluginRunning) btPluginStatus += "running";
 		else btPluginStatus += "not running";
 		TransportProperties btProps = props.get(new TransportId("bt"));
-		if(btProps != null)
+		if (btProps != null)
 			btPluginStatus += "\nAddress: " + btProps.get("address");
 		statusMap.put("Bluetooth plugin:", btPluginStatus);
 
@@ -432,16 +432,16 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 			Pattern pattern = Pattern.compile(".*\\( *" + pid + "\\).*");
 			Process process = runtime.exec("logcat -d -v time *:I");
 			Scanner scanner = new Scanner(process.getInputStream());
-			while(scanner.hasNextLine()) {
+			while (scanner.hasNextLine()) {
 				String line = scanner.nextLine();
-				if(pattern.matcher(line).matches()) {
+				if (pattern.matcher(line).matches()) {
 					log.append(line);
 					log.append('\n');
 				}
 			}
 			scanner.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		statusMap.put("Debugging log:", log.toString());
 
@@ -449,9 +449,9 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 	}
 
 	private String capitalize(String s) {
-		if(StringUtils.isNullOrEmpty(s)) return s;
+		if (StringUtils.isNullOrEmpty(s)) return s;
 		char first = s.charAt(0);
-		if(Character.isUpperCase(first)) return s;
+		if (Character.isUpperCase(first)) return s;
 		return Character.toUpperCase(first) + s.substring(1);
 	}
 
@@ -468,10 +468,10 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 				try {
 					File shared = Environment.getExternalStorageDirectory();
 					temp = File.createTempFile("debug", ".txt", shared);
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Writing to " + temp.getPath());
 					PrintStream p = new PrintStream(new FileOutputStream(temp));
-					for(Entry<String, String> e : result.entrySet()) {
+					for (Entry<String, String> e : result.entrySet()) {
 						p.println(e.getKey());
 						p.println(e.getValue());
 						p.println();
@@ -479,8 +479,8 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
 					p.flush();
 					p.close();
 					sendEmail(Uri.fromFile(temp));
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/contact/ContactListActivity.java b/briar-android/src/org/briarproject/android/contact/ContactListActivity.java
index ea9cda9370..630c4dec99 100644
--- a/briar-android/src/org/briarproject/android/contact/ContactListActivity.java
+++ b/briar-android/src/org/briarproject/android/contact/ContactListActivity.java
@@ -138,22 +138,22 @@ EventListener {
 			public void run() {
 				try {
 					long now = System.currentTimeMillis();
-					for(Contact c : db.getContacts()) {
+					for (Contact c : db.getContacts()) {
 						try {
 							GroupId inbox = db.getInboxGroupId(c.getId());
 							Collection<MessageHeader> headers =
 									db.getInboxMessageHeaders(c.getId());
 							displayContact(c, inbox, headers);
-						} catch(NoSuchContactException e) {
+						} catch (NoSuchContactException e) {
 							// Continue
 						}
 					}
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Full load took " + duration + " ms");
 					hideProgressBar();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -181,7 +181,7 @@ EventListener {
 				boolean connected = connectionRegistry.isConnected(c.getId());
 				// Remove the old item, if any
 				ContactListItem item = findItem(c.getId());
-				if(item != null) adapter.remove(item);
+				if (item != null) adapter.remove(item);
 				// Add a new item
 				adapter.add(new ContactListItem(c, connected, inbox, headers));
 				adapter.sort(ContactListItemComparator.INSTANCE);
@@ -193,7 +193,7 @@ EventListener {
 	private void hideProgressBar() {
 		runOnUiThread(new Runnable() {
 			public void run() {
-				if(adapter.isEmpty()) empty.setVisibility(VISIBLE);
+				if (adapter.isEmpty()) empty.setVisibility(VISIBLE);
 				else list.setVisibility(VISIBLE);
 				loading.setVisibility(GONE);
 			}
@@ -202,9 +202,9 @@ EventListener {
 
 	private ContactListItem findItem(ContactId c) {
 		int count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
+		for (int i = 0; i < count; i++) {
 			ContactListItem item = adapter.getItem(i);
-			if(item.getContact().getId().equals(c)) return item;
+			if (item.getContact().getId().equals(c)) return item;
 		}
 		return null; // Not found
 	}
@@ -243,7 +243,7 @@ EventListener {
 
 	@Override
 	public boolean onContextItemSelected(MenuItem menuItem) {
-		if(menuItem.getItemId() == MENU_ITEM_DELETE) {
+		if (menuItem.getItemId() == MENU_ITEM_DELETE) {
 			ContextMenuInfo info = menuItem.getMenuInfo();
 			int position = ((AdapterContextMenuInfo) info).position;
 			ContactListItem item = adapter.getItem(position);
@@ -259,8 +259,8 @@ EventListener {
 			public void run() {
 				try {
 					db.removeContact(c);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -268,21 +268,21 @@ EventListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof ContactAddedEvent) {
+		if (e instanceof ContactAddedEvent) {
 			loadContacts();
-		} else if(e instanceof ContactConnectedEvent) {
+		} else if (e instanceof ContactConnectedEvent) {
 			setConnected(((ContactConnectedEvent) e).getContactId(), true);
-		} else if(e instanceof ContactDisconnectedEvent) {
+		} else if (e instanceof ContactDisconnectedEvent) {
 			setConnected(((ContactDisconnectedEvent) e).getContactId(), false);
-		} else if(e instanceof ContactRemovedEvent) {
+		} else if (e instanceof ContactRemovedEvent) {
 			LOG.info("Contact removed");
 			removeItem(((ContactRemovedEvent) e).getContactId());
-		} else if(e instanceof MessageAddedEvent) {
+		} else if (e instanceof MessageAddedEvent) {
 			LOG.info("Message added, reloading");
 			ContactId source = ((MessageAddedEvent) e).getContactId();
-			if(source == null) loadContacts();
+			if (source == null) loadContacts();
 			else reloadContact(source);
-		} else if(e instanceof MessageExpiredEvent) {
+		} else if (e instanceof MessageExpiredEvent) {
 			LOG.info("Message expired, reloading");
 			loadContacts();
 		}
@@ -296,13 +296,13 @@ EventListener {
 					Collection<MessageHeader> headers =
 							db.getInboxMessageHeaders(c);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Partial load took " + duration + " ms");
 					updateItem(c, headers);
-				} catch(NoSuchContactException e) {
+				} catch (NoSuchContactException e) {
 					removeItem(c);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -314,7 +314,7 @@ EventListener {
 		runOnUiThread(new Runnable() {
 			public void run() {
 				ContactListItem item = findItem(c);
-				if(item != null) {
+				if (item != null) {
 					item.setHeaders(headers);
 					adapter.notifyDataSetChanged();
 				}
@@ -326,10 +326,10 @@ EventListener {
 		runOnUiThread(new Runnable() {
 			public void run() {
 				ContactListItem item = findItem(c);
-				if(item != null) {
+				if (item != null) {
 					adapter.remove(item);
 					adapter.notifyDataSetChanged();
-					if(adapter.isEmpty()) {
+					if (adapter.isEmpty()) {
 						empty.setVisibility(VISIBLE);
 						list.setVisibility(GONE);
 					}
@@ -342,7 +342,7 @@ EventListener {
 		runOnUiThread(new Runnable() {
 			public void run() {
 				ContactListItem item = findItem(c);
-				if(item != null) {
+				if (item != null) {
 					item.setConnected(connected);
 					adapter.notifyDataSetChanged();
 				}
diff --git a/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java b/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java
index 098502bb5d..1acb52435d 100644
--- a/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java
+++ b/briar-android/src/org/briarproject/android/contact/ContactListAdapter.java
@@ -40,12 +40,12 @@ class ContactListAdapter extends ArrayAdapter<ContactListItem> {
 		layout.setOrientation(HORIZONTAL);
 		layout.setGravity(CENTER_VERTICAL);
 		int unread = item.getUnreadCount();
-		if(unread > 0)
+		if (unread > 0)
 			layout.setBackgroundColor(res.getColor(R.color.unread_background));
 
 		ImageView bulb = new ImageView(ctx);
 		bulb.setPadding(pad, pad, pad, pad);
-		if(item.isConnected())
+		if (item.isConnected())
 			bulb.setImageResource(R.drawable.contact_connected);
 		else bulb.setImageResource(R.drawable.contact_disconnected);
 		layout.addView(bulb);
@@ -57,11 +57,11 @@ class ContactListAdapter extends ArrayAdapter<ContactListItem> {
 		name.setEllipsize(END);
 		name.setPadding(0, pad, pad, pad);
 		String contactName = item.getContact().getAuthor().getName();
-		if(unread > 0) name.setText(contactName + " (" + unread + ")");
+		if (unread > 0) name.setText(contactName + " (" + unread + ")");
 		else name.setText(contactName);
 		layout.addView(name);
 
-		if(item.isEmpty()) {
+		if (item.isEmpty()) {
 			TextView noMessages = new TextView(ctx);
 			noMessages.setPadding(pad, pad, pad, pad);
 			noMessages.setTextColor(res.getColor(R.color.no_private_messages));
diff --git a/briar-android/src/org/briarproject/android/contact/ContactListItem.java b/briar-android/src/org/briarproject/android/contact/ContactListItem.java
index 9d10e9be7c..276ae9178f 100644
--- a/briar-android/src/org/briarproject/android/contact/ContactListItem.java
+++ b/briar-android/src/org/briarproject/android/contact/ContactListItem.java
@@ -27,10 +27,10 @@ class ContactListItem {
 		empty = headers.isEmpty();
 		timestamp = 0;
 		unread = 0;
-		if(!empty) {
-			for(MessageHeader h : headers) {
-				if(h.getTimestamp() > timestamp) timestamp = h.getTimestamp();
-				if(!h.isRead()) unread++;
+		if (!empty) {
+			for (MessageHeader h : headers) {
+				if (h.getTimestamp() > timestamp) timestamp = h.getTimestamp();
+				if (!h.isRead()) unread++;
 			}
 		}
 	}
diff --git a/briar-android/src/org/briarproject/android/contact/ConversationActivity.java b/briar-android/src/org/briarproject/android/contact/ConversationActivity.java
index b951ae91ee..2375da4a8f 100644
--- a/briar-android/src/org/briarproject/android/contact/ConversationActivity.java
+++ b/briar-android/src/org/briarproject/android/contact/ConversationActivity.java
@@ -111,7 +111,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
 
 		Intent i = getIntent();
 		int id = i.getIntExtra("briar.CONTACT_ID", -1);
-		if(id == -1) throw new IllegalStateException();
+		if (id == -1) throw new IllegalStateException();
 		contactId = new ContactId(id);
 
 		Intent data = new Intent();
@@ -206,17 +206,17 @@ implements EventListener, OnClickListener, OnItemClickListener {
 					groupId = db.getInboxGroupId(contactId);
 					group = db.getGroup(groupId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO)) {
+					if (LOG.isLoggable(INFO)) {
 						LOG.info("Loading contact and group took "
 								+ duration + " ms");
 					}
 					displayContactName();
-				} catch(NoSuchContactException e) {
+				} catch (NoSuchContactException e) {
 					finishOnUiThread();
-				} catch(NoSuchSubscriptionException e) {
+				} catch (NoSuchSubscriptionException e) {
 					finishOnUiThread();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -239,13 +239,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
 					Collection<MessageHeader> headers =
 							db.getInboxMessageHeaders(contactId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading headers took " + duration + " ms");
 					displayHeaders(headers);
-				} catch(NoSuchContactException e) {
+				} catch (NoSuchContactException e) {
 					finishOnUiThread();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -259,16 +259,16 @@ implements EventListener, OnClickListener, OnItemClickListener {
 				setTitle(contactName);
 				sendButton.setEnabled(true);
 				adapter.clear();
-				if(headers.isEmpty()) {
+				if (headers.isEmpty()) {
 					empty.setVisibility(VISIBLE);
 					list.setVisibility(GONE);
 				} else {
 					empty.setVisibility(GONE);
 					list.setVisibility(VISIBLE);
-					for(MessageHeader h : headers) {
+					for (MessageHeader h : headers) {
 						ConversationItem item = new ConversationItem(h);
 						byte[] body = bodyCache.get(h.getId());
-						if(body == null) loadMessageBody(h);
+						if (body == null) loadMessageBody(h);
 						else item.setBody(body);
 						adapter.add(item);
 					}
@@ -288,13 +288,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
 					long now = System.currentTimeMillis();
 					byte[] body = db.getMessageBody(h.getId());
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading message took " + duration + " ms");
 					displayMessageBody(h.getId(), body);
-				} catch(NoSuchMessageException e) {
+				} catch (NoSuchMessageException e) {
 					// The item will be removed when we get the event
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -306,9 +306,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
 			public void run() {
 				bodyCache.put(m, body);
 				int count = adapter.getCount();
-				for(int i = 0; i < count; i++) {
+				for (int i = 0; i < count; i++) {
 					ConversationItem item = adapter.getItem(i);
-					if(item.getHeader().getId().equals(m)) {
+					if (item.getHeader().getId().equals(m)) {
 						item.setBody(body);
 						adapter.notifyDataSetChanged();
 						// Scroll to the bottom
@@ -323,9 +323,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
 	@Override
 	protected void onActivityResult(int request, int result, Intent data) {
 		super.onActivityResult(request, result, data);
-		if(request == REQUEST_READ && result == RESULT_PREV_NEXT) {
+		if (request == REQUEST_READ && result == RESULT_PREV_NEXT) {
 			int position = data.getIntExtra("briar.POSITION", -1);
-			if(position >= 0 && position < adapter.getCount())
+			if (position >= 0 && position < adapter.getCount())
 				displayMessage(position);
 		}
 	}
@@ -334,19 +334,19 @@ implements EventListener, OnClickListener, OnItemClickListener {
 	public void onPause() {
 		super.onPause();
 		eventBus.removeListener(this);
-		if(isFinishing()) markMessagesRead();
+		if (isFinishing()) markMessagesRead();
 	}
 
 	private void markMessagesRead() {
 		notificationManager.clearPrivateMessageNotification(contactId);
 		List<MessageId> unread = new ArrayList<MessageId>();
 		int count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
+		for (int i = 0; i < count; i++) {
 			MessageHeader h = adapter.getItem(i).getHeader();
-			if(!h.isRead()) unread.add(h.getId());
+			if (!h.isRead()) unread.add(h.getId());
 		}
-		if(unread.isEmpty()) return;
-		if(LOG.isLoggable(INFO))
+		if (unread.isEmpty()) return;
+		if (LOG.isLoggable(INFO))
 			LOG.info("Marking " + unread.size() + " messages read");
 		markMessagesRead(Collections.unmodifiableList(unread));
 	}
@@ -356,12 +356,12 @@ implements EventListener, OnClickListener, OnItemClickListener {
 			public void run() {
 				try {
 					long now = System.currentTimeMillis();
-					for(MessageId m : unread) db.setReadFlag(m, true);
+					for (MessageId m : unread) db.setReadFlag(m, true);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Marking read took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -369,24 +369,24 @@ implements EventListener, OnClickListener, OnItemClickListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof ContactRemovedEvent) {
+		if (e instanceof ContactRemovedEvent) {
 			ContactRemovedEvent c = (ContactRemovedEvent) e;
-			if(c.getContactId().equals(contactId)) {
+			if (c.getContactId().equals(contactId)) {
 				LOG.info("Contact removed");
 				finishOnUiThread();
 			}
-		} else if(e instanceof MessageAddedEvent) {
+		} else if (e instanceof MessageAddedEvent) {
 			GroupId g = ((MessageAddedEvent) e).getGroup().getId();
-			if(g.equals(groupId)) {
+			if (g.equals(groupId)) {
 				LOG.info("Message added, reloading");
 				loadHeaders();
 			}
-		} else if(e instanceof MessageExpiredEvent) {
+		} else if (e instanceof MessageExpiredEvent) {
 			LOG.info("Message expired, reloading");
 			loadHeaders();
-		} else if(e instanceof MessagesAckedEvent) {
+		} else if (e instanceof MessagesAckedEvent) {
 			MessagesAckedEvent m = (MessagesAckedEvent) e;
-			if(m.getContactId().equals(contactId)) {
+			if (m.getContactId().equals(contactId)) {
 				LOG.info("Messages acked");
 				markMessagesDelivered(m.getMessageIds());
 			}
@@ -399,21 +399,21 @@ implements EventListener, OnClickListener, OnItemClickListener {
 				Set<MessageId> ackedSet = new HashSet<MessageId>(acked);
 				boolean changed = false;
 				int count = adapter.getCount();
-				for(int i = 0; i < count; i++) {
+				for (int i = 0; i < count; i++) {
 					ConversationItem item = adapter.getItem(i);
-					if(ackedSet.contains(item.getHeader().getId())) {
+					if (ackedSet.contains(item.getHeader().getId())) {
 						item.setDelivered(true);
 						changed = true;
 					}
 				}
-				if(changed) adapter.notifyDataSetChanged();
+				if (changed) adapter.notifyDataSetChanged();
 			}
 		});
 	}
 
 	public void onClick(View view) {
 		String message = content.getText().toString();
-		if(message.equals("")) return;
+		if (message.equals("")) return;
 		long timestamp = System.currentTimeMillis();
 		timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
 		createMessage(StringUtils.toUtf8(message), timestamp);
@@ -426,9 +426,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
 		// Don't use an earlier timestamp than the newest message
 		long timestamp = 0;
 		int count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
+		for (int i = 0; i < count; i++) {
 			long t = adapter.getItem(i).getHeader().getTimestamp();
-			if(t > timestamp) timestamp = t;
+			if (t > timestamp) timestamp = t;
 		}
 		return timestamp + 1;
 	}
@@ -440,9 +440,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
 					Message m = messageFactory.createAnonymousMessage(null,
 							group, "text/plain", timestamp, body);
 					storeMessage(m);
-				} catch(GeneralSecurityException e) {
+				} catch (GeneralSecurityException e) {
 					throw new RuntimeException(e);
-				} catch(IOException e) {
+				} catch (IOException e) {
 					throw new RuntimeException(e);
 				}
 			}
@@ -456,10 +456,10 @@ implements EventListener, OnClickListener, OnItemClickListener {
 					long now = System.currentTimeMillis();
 					db.addLocalMessage(m);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Storing message took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java
index 249392b545..14699ab724 100644
--- a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java
+++ b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java
@@ -45,17 +45,17 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
 
 		LinearLayout layout = new LinearLayout(ctx);
 		layout.setOrientation(VERTICAL);
-		if(header.isLocal()) layout.setPadding(3 * pad, 0, 0, 0);
+		if (header.isLocal()) layout.setPadding(3 * pad, 0, 0, 0);
 		else layout.setPadding(0, 0, 3 * pad, 0);
 
 		int background = res.getColor(R.color.private_message_background);
 
 		View content;
-		if(item.getBody() == null) {
+		if (item.getBody() == null) {
 			TextView ellipsis = new TextView(ctx);
 			ellipsis.setText("\u2026");
 			content = ellipsis;
-		} else if(header.getContentType().equals("text/plain")) {
+		} else if (header.getContentType().equals("text/plain")) {
 			TextView text = new TextView(ctx);
 			text.setText(StringUtils.fromUtf8(item.getBody()));
 			content = text;
@@ -69,7 +69,7 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
 		content.setPadding(pad, pad, pad, 0);
 		layout.addView(content);
 
-		if(header.isLocal()) {
+		if (header.isLocal()) {
 			LinearLayout footer = new LinearLayout(ctx);
 			footer.setLayoutParams(MATCH_WRAP);
 			footer.setOrientation(HORIZONTAL);
@@ -82,7 +82,7 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
 			ImageView delivered = new ImageView(ctx);
 			delivered.setPadding(0, 0, pad, 0);
 			delivered.setImageResource(R.drawable.message_delivered);
-			if(!item.isDelivered()) delivered.setVisibility(INVISIBLE);
+			if (!item.isDelivered()) delivered.setVisibility(INVISIBLE);
 			footer.addView(delivered);
 
 			TextView date = new TextView(ctx);
diff --git a/briar-android/src/org/briarproject/android/contact/ConversationItemComparator.java b/briar-android/src/org/briarproject/android/contact/ConversationItemComparator.java
index 6b5f3ec77e..76eb1d28dd 100644
--- a/briar-android/src/org/briarproject/android/contact/ConversationItemComparator.java
+++ b/briar-android/src/org/briarproject/android/contact/ConversationItemComparator.java
@@ -11,8 +11,8 @@ class ConversationItemComparator implements Comparator<ConversationItem> {
 		// The oldest message comes first
 		long aTime = a.getHeader().getTimestamp();
 		long bTime = b.getHeader().getTimestamp();
-		if(aTime < bTime) return -1;
-		if(aTime > bTime) return 1;
+		if (aTime < bTime) return -1;
+		if (aTime > bTime) return 1;
 		return 0;
 	}
 }
diff --git a/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java b/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java
index 2dfafbef4e..abbbb5fe90 100644
--- a/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java
+++ b/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java
@@ -68,27 +68,27 @@ implements OnClickListener {
 
 		Intent i = getIntent();
 		contactName = i.getStringExtra("briar.CONTACT_NAME");
-		if(contactName == null) throw new IllegalStateException();
+		if (contactName == null) throw new IllegalStateException();
 		setTitle(contactName);
 		byte[] b = i.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		localAuthorId = new AuthorId(b);
 		String authorName = i.getStringExtra("briar.AUTHOR_NAME");
-		if(authorName == null) throw new IllegalStateException();
+		if (authorName == null) throw new IllegalStateException();
 		b = i.getByteArrayExtra("briar.MESSAGE_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		messageId = new MessageId(b);
 		b = i.getByteArrayExtra("briar.GROUP_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		groupId = new GroupId(b);
 		String contentType = i.getStringExtra("briar.CONTENT_TYPE");
-		if(contentType == null) throw new IllegalStateException();
+		if (contentType == null) throw new IllegalStateException();
 		timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
-		if(timestamp == -1) throw new IllegalStateException();
+		if (timestamp == -1) throw new IllegalStateException();
 		minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
-		if(minTimestamp == -1) throw new IllegalStateException();
+		if (minTimestamp == -1) throw new IllegalStateException();
 		position = i.getIntExtra("briar.POSITION", -1);
-		if(position == -1) throw new IllegalStateException();
+		if (position == -1) throw new IllegalStateException();
 
 		LinearLayout layout = new LinearLayout(this);
 		layout.setLayoutParams(MATCH_WRAP);
@@ -118,7 +118,7 @@ implements OnClickListener {
 		header.addView(date);
 		message.addView(header);
 
-		if(contentType.equals("text/plain")) {
+		if (contentType.equals("text/plain")) {
 			// Load and display the message body
 			content = new TextView(this);
 			content.setPadding(pad, 0, pad, pad);
@@ -164,7 +164,7 @@ implements OnClickListener {
 	@Override
 	public void onPause() {
 		super.onPause();
-		if(isFinishing()) markMessageRead();
+		if (isFinishing()) markMessageRead();
 	}
 
 	private void markMessageRead() {
@@ -174,10 +174,10 @@ implements OnClickListener {
 					long now = System.currentTimeMillis();
 					db.setReadFlag(messageId, true);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Marking read took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -191,13 +191,13 @@ implements OnClickListener {
 					long now = System.currentTimeMillis();
 					byte[] body = db.getMessageBody(messageId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading message took " + duration + " ms");
 					displayMessageBody(StringUtils.fromUtf8(body));
-				} catch(NoSuchMessageException e) {
+				} catch (NoSuchMessageException e) {
 					finishOnUiThread();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -213,17 +213,17 @@ implements OnClickListener {
 	}
 
 	public void onClick(View view) {
-		if(view == prevButton) {
+		if (view == prevButton) {
 			Intent i = new Intent();
 			i.putExtra("briar.POSITION", position - 1);
 			setResult(RESULT_PREV_NEXT, i);
 			finish();
-		} else if(view == nextButton) {
+		} else if (view == nextButton) {
 			Intent i = new Intent();
 			i.putExtra("briar.POSITION", position + 1);
 			setResult(RESULT_PREV_NEXT, i);
 			finish();
-		} else if(view == replyButton) {
+		} else if (view == replyButton) {
 			Intent i = new Intent(this, WritePrivateMessageActivity.class);
 			i.putExtra("briar.CONTACT_NAME", contactName);
 			i.putExtra("briar.GROUP_ID", groupId.getBytes());
diff --git a/briar-android/src/org/briarproject/android/contact/SelectContactsDialog.java b/briar-android/src/org/briarproject/android/contact/SelectContactsDialog.java
index b26f3219cf..0cbec574a6 100644
--- a/briar-android/src/org/briarproject/android/contact/SelectContactsDialog.java
+++ b/briar-android/src/org/briarproject/android/contact/SelectContactsDialog.java
@@ -35,13 +35,13 @@ public class SelectContactsDialog implements OnMultiChoiceClickListener {
 	}
 
 	public Dialog build(Context ctx) {
-		if(listener == null || contacts == null || selected == null)
+		if (listener == null || contacts == null || selected == null)
 			throw new IllegalStateException();
 		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
 		int size = contacts.size();
 		String[] names = new String[size];
 		boolean[] checked = new boolean[size];
-		for(int i = 0; i < size; i++) {
+		for (int i = 0; i < size; i++) {
 			Contact c = contacts.get(i);
 			names[i] = c.getAuthor().getName();
 			checked[i] = selected.contains(c.getId());
@@ -63,7 +63,7 @@ public class SelectContactsDialog implements OnMultiChoiceClickListener {
 	}
 
 	public void onClick(DialogInterface dialog, int which, boolean isChecked) {
-		if(isChecked) selected.add(contacts.get(which).getId());
+		if (isChecked) selected.add(contacts.get(which).getId());
 		else selected.remove(contacts.get(which).getId());
 	}
 
diff --git a/briar-android/src/org/briarproject/android/contact/WritePrivateMessageActivity.java b/briar-android/src/org/briarproject/android/contact/WritePrivateMessageActivity.java
index 744170e03a..b173983499 100644
--- a/briar-android/src/org/briarproject/android/contact/WritePrivateMessageActivity.java
+++ b/briar-android/src/org/briarproject/android/contact/WritePrivateMessageActivity.java
@@ -78,18 +78,18 @@ implements OnClickListener {
 
 		Intent i = getIntent();
 		contactName = i.getStringExtra("briar.CONTACT_NAME");
-		if(contactName == null) throw new IllegalStateException();
+		if (contactName == null) throw new IllegalStateException();
 		setTitle(contactName);
 		byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		groupId = new GroupId(b);
 		b = i.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
-		if(minTimestamp == -1) throw new IllegalStateException();
+		if (minTimestamp == -1) throw new IllegalStateException();
 		localAuthorId = new AuthorId(b);
 		b = i.getByteArrayExtra("briar.PARENT_ID");
-		if(b != null) parentId = new MessageId(b);
+		if (b != null) parentId = new MessageId(b);
 
 		LinearLayout layout = new LinearLayout(this);
 		layout.setLayoutParams(MATCH_WRAP);
@@ -138,7 +138,7 @@ implements OnClickListener {
 	@Override
 	public void onResume() {
 		super.onResume();
-		if(localAuthor == null || group == null) loadAuthorAndGroup();
+		if (localAuthor == null || group == null) loadAuthorAndGroup();
 	}
 
 	private void loadAuthorAndGroup() {
@@ -149,15 +149,15 @@ implements OnClickListener {
 					localAuthor = db.getLocalAuthor(localAuthorId);
 					group = db.getGroup(groupId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Load took " + duration + " ms");
 					displayLocalAuthor();
-				} catch(NoSuchContactException e) {
+				} catch (NoSuchContactException e) {
 					finishOnUiThread();
-				} catch(NoSuchSubscriptionException e) {
+				} catch (NoSuchSubscriptionException e) {
 					finishOnUiThread();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -177,7 +177,7 @@ implements OnClickListener {
 
 	public void onClick(View view) {
 		String message = content.getText().toString();
-		if(message.equals("")) return;
+		if (message.equals("")) return;
 		createMessage(StringUtils.toUtf8(message));
 		Toast.makeText(this, R.string.message_sent_toast, LENGTH_LONG).show();
 		finish();
@@ -193,9 +193,9 @@ implements OnClickListener {
 					Message m = messageFactory.createAnonymousMessage(parentId,
 							group, "text/plain", timestamp, body);
 					storeMessage(m);
-				} catch(GeneralSecurityException e) {
+				} catch (GeneralSecurityException e) {
 					throw new RuntimeException(e);
-				} catch(IOException e) {
+				} catch (IOException e) {
 					throw new RuntimeException(e);
 				}
 			}
@@ -209,10 +209,10 @@ implements OnClickListener {
 					long now = System.currentTimeMillis();
 					db.addLocalMessage(m);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Storing message took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/groups/AvailableGroupsActivity.java b/briar-android/src/org/briarproject/android/groups/AvailableGroupsActivity.java
index 01d5bcfcd8..e1fd39964b 100644
--- a/briar-android/src/org/briarproject/android/groups/AvailableGroupsActivity.java
+++ b/briar-android/src/org/briarproject/android/groups/AvailableGroupsActivity.java
@@ -78,21 +78,21 @@ implements EventListener, OnItemClickListener {
 					Collection<GroupContacts> available =
 							new ArrayList<GroupContacts>();
 					long now = System.currentTimeMillis();
-					for(Group g : db.getAvailableGroups()) {
+					for (Group g : db.getAvailableGroups()) {
 						try {
 							GroupId id = g.getId();
 							Collection<Contact> c = db.getSubscribers(id);
 							available.add(new GroupContacts(g, c));
-						} catch(NoSuchSubscriptionException e) {
+						} catch (NoSuchSubscriptionException e) {
 							continue;
 						}
 					}
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Load took " + duration + " ms");
 					displayGroups(available);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -102,13 +102,13 @@ implements EventListener, OnItemClickListener {
 	private void displayGroups(final Collection<GroupContacts> available) {
 		runOnUiThread(new Runnable() {
 			public void run() {
-				if(available.isEmpty()) {
+				if (available.isEmpty()) {
 					LOG.info("No groups available, finishing");
 					finish();
 				} else {
 					setContentView(list);
 					adapter.clear();
-					for(GroupContacts g : available)
+					for (GroupContacts g : available)
 						adapter.add(new AvailableGroupsItem(g));
 					adapter.sort(AvailableGroupsItemComparator.INSTANCE);
 					adapter.notifyDataSetChanged();
@@ -124,13 +124,13 @@ implements EventListener, OnItemClickListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof RemoteSubscriptionsUpdatedEvent) {
+		if (e instanceof RemoteSubscriptionsUpdatedEvent) {
 			LOG.info("Remote subscriptions changed, reloading");
 			loadGroups();
-		} else if(e instanceof SubscriptionAddedEvent) {
+		} else if (e instanceof SubscriptionAddedEvent) {
 			LOG.info("Subscription added, reloading");
 			loadGroups();
-		} else if(e instanceof SubscriptionRemovedEvent) {
+		} else if (e instanceof SubscriptionRemovedEvent) {
 			LOG.info("Subscription removed, reloading");
 			loadGroups();
 		}
@@ -140,7 +140,7 @@ implements EventListener, OnItemClickListener {
 			long id) {
 		AvailableGroupsItem item = adapter.getItem(position);
 		Collection<ContactId> visible = new ArrayList<ContactId>();
-		for(Contact c : item.getContacts()) visible.add(c.getId());
+		for (Contact c : item.getContacts()) visible.add(c.getId());
 		addSubscription(item.getGroup(), visible);
 		String subscribed = getString(R.string.subscribed_toast);
 		Toast.makeText(this, subscribed, LENGTH_SHORT).show();
@@ -153,8 +153,8 @@ implements EventListener, OnItemClickListener {
 				try {
 					db.addGroup(g);
 					db.setVisibility(g.getId(), visible);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/groups/AvailableGroupsAdapter.java b/briar-android/src/org/briarproject/android/groups/AvailableGroupsAdapter.java
index 7e0528f14b..ec52754c26 100644
--- a/briar-android/src/org/briarproject/android/groups/AvailableGroupsAdapter.java
+++ b/briar-android/src/org/briarproject/android/groups/AvailableGroupsAdapter.java
@@ -47,7 +47,7 @@ class AvailableGroupsAdapter extends ArrayAdapter<AvailableGroupsItem> {
 		TextView status = new TextView(ctx);
 		status.setPadding(pad, 0, pad, pad);
 		Collection<String> names = new ArrayList<String>();
-		for(Contact c : item.getContacts()) names.add(c.getAuthor().getName());
+		for (Contact c : item.getContacts()) names.add(c.getAuthor().getName());
 		String format = ctx.getString(R.string.shared_by_format);
 		status.setText(String.format(format, StringUtils.join(names, ", ")));
 		layout.addView(status);
diff --git a/briar-android/src/org/briarproject/android/groups/AvailableGroupsItemComparator.java b/briar-android/src/org/briarproject/android/groups/AvailableGroupsItemComparator.java
index 2b9fce5fcd..8840135590 100644
--- a/briar-android/src/org/briarproject/android/groups/AvailableGroupsItemComparator.java
+++ b/briar-android/src/org/briarproject/android/groups/AvailableGroupsItemComparator.java
@@ -8,7 +8,7 @@ class AvailableGroupsItemComparator implements Comparator<AvailableGroupsItem> {
 			new AvailableGroupsItemComparator();
 
 	public int compare(AvailableGroupsItem a, AvailableGroupsItem b) {
-		if(a == b) return 0;
+		if (a == b) return 0;
 		String aName = a.getGroup().getName();
 		String bName = b.getGroup().getName();
 		return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
diff --git a/briar-android/src/org/briarproject/android/groups/CreateGroupActivity.java b/briar-android/src/org/briarproject/android/groups/CreateGroupActivity.java
index 85d16deb29..120de84fe7 100644
--- a/briar-android/src/org/briarproject/android/groups/CreateGroupActivity.java
+++ b/briar-android/src/org/briarproject/android/groups/CreateGroupActivity.java
@@ -105,7 +105,7 @@ implements OnEditorActionListener, OnClickListener {
 	}
 
 	private void enableOrDisableCreateButton() {
-		if(progress == null) return; // Not created yet
+		if (progress == null) return; // Not created yet
 		createForumButton.setEnabled(validateName());
 	}
 
@@ -116,7 +116,7 @@ implements OnEditorActionListener, OnClickListener {
 
 	private boolean validateName() {
 		int length = StringUtils.toUtf8(nameEntry.getText().toString()).length;
-		if(length > MAX_GROUP_NAME_LENGTH) {
+		if (length > MAX_GROUP_NAME_LENGTH) {
 			feedback.setText(R.string.name_too_long);
 			return false;
 		}
@@ -125,9 +125,9 @@ implements OnEditorActionListener, OnClickListener {
 	}
 
 	public void onClick(View view) {
-		if(view == createForumButton) {
+		if (view == createForumButton) {
 			hideSoftKeyboard();
-			if(!validateName()) return;
+			if (!validateName()) return;
 			createForumButton.setVisibility(GONE);
 			progress.setVisibility(VISIBLE);
 			storeGroup(nameEntry.getText().toString());
@@ -142,11 +142,11 @@ implements OnEditorActionListener, OnClickListener {
 					long now = System.currentTimeMillis();
 					db.addGroup(g);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Storing group took " + duration + " ms");
 					displayGroup(g);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					finishOnUiThread();
 				}
diff --git a/briar-android/src/org/briarproject/android/groups/GroupActivity.java b/briar-android/src/org/briarproject/android/groups/GroupActivity.java
index ee516fc919..dcf94c9079 100644
--- a/briar-android/src/org/briarproject/android/groups/GroupActivity.java
+++ b/briar-android/src/org/briarproject/android/groups/GroupActivity.java
@@ -83,10 +83,10 @@ OnClickListener, OnItemClickListener {
 
 		Intent i = getIntent();
 		byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		groupId = new GroupId(b);
 		String name = i.getStringExtra("briar.GROUP_NAME");
-		if(name != null) setTitle(name);
+		if (name != null) setTitle(name);
 
 		LinearLayout layout = new LinearLayout(this);
 		layout.setLayoutParams(MATCH_MATCH);
@@ -155,13 +155,13 @@ OnClickListener, OnItemClickListener {
 					long now = System.currentTimeMillis();
 					group = db.getGroup(groupId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading group " + duration + " ms");
 					displayGroupName();
-				} catch(NoSuchSubscriptionException e) {
+				} catch (NoSuchSubscriptionException e) {
 					finishOnUiThread();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -184,13 +184,13 @@ OnClickListener, OnItemClickListener {
 					Collection<MessageHeader> headers =
 							db.getMessageHeaders(groupId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Load took " + duration + " ms");
 					displayHeaders(headers);
-				} catch(NoSuchSubscriptionException e) {
+				} catch (NoSuchSubscriptionException e) {
 					finishOnUiThread();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -202,16 +202,16 @@ OnClickListener, OnItemClickListener {
 			public void run() {
 				loading.setVisibility(GONE);
 				adapter.clear();
-				if(headers.isEmpty()) {
+				if (headers.isEmpty()) {
 					empty.setVisibility(VISIBLE);
 					list.setVisibility(GONE);
 				} else {
 					empty.setVisibility(GONE);
 					list.setVisibility(VISIBLE);
-					for(MessageHeader h : headers) {
+					for (MessageHeader h : headers) {
 						GroupItem item = new GroupItem(h);
 						byte[] body = bodyCache.get(h.getId());
-						if(body == null) loadMessageBody(h);
+						if (body == null) loadMessageBody(h);
 						else item.setBody(body);
 						adapter.add(item);
 					}
@@ -231,13 +231,13 @@ OnClickListener, OnItemClickListener {
 					long now = System.currentTimeMillis();
 					byte[] body = db.getMessageBody(h.getId());
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading message took " + duration + " ms");
 					displayMessage(h.getId(), body);
-				} catch(NoSuchMessageException e) {
+				} catch (NoSuchMessageException e) {
 					// The item will be removed when we get the event
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -249,9 +249,9 @@ OnClickListener, OnItemClickListener {
 			public void run() {
 				bodyCache.put(m, body);
 				int count = adapter.getCount();
-				for(int i = 0; i < count; i++) {
+				for (int i = 0; i < count; i++) {
 					GroupItem item = adapter.getItem(i);
-					if(item.getHeader().getId().equals(m)) {
+					if (item.getHeader().getId().equals(m)) {
 						item.setBody(body);
 						adapter.notifyDataSetChanged();
 						// Scroll to the bottom
@@ -266,9 +266,9 @@ OnClickListener, OnItemClickListener {
 	@Override
 	protected void onActivityResult(int request, int result, Intent data) {
 		super.onActivityResult(request, result, data);
-		if(request == REQUEST_READ && result == RESULT_PREV_NEXT) {
+		if (request == REQUEST_READ && result == RESULT_PREV_NEXT) {
 			int position = data.getIntExtra("briar.POSITION", -1);
-			if(position >= 0 && position < adapter.getCount())
+			if (position >= 0 && position < adapter.getCount())
 				displayMessage(position);
 		}
 	}
@@ -277,19 +277,19 @@ OnClickListener, OnItemClickListener {
 	public void onPause() {
 		super.onPause();
 		eventBus.removeListener(this);
-		if(isFinishing()) markMessagesRead();
+		if (isFinishing()) markMessagesRead();
 	}
 
 	private void markMessagesRead() {
 		notificationManager.clearGroupPostNotification(groupId);
 		List<MessageId> unread = new ArrayList<MessageId>();
 		int count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
+		for (int i = 0; i < count; i++) {
 			MessageHeader h = adapter.getItem(i).getHeader();
-			if(!h.isRead()) unread.add(h.getId());
+			if (!h.isRead()) unread.add(h.getId());
 		}
-		if(unread.isEmpty()) return;
-		if(LOG.isLoggable(INFO))
+		if (unread.isEmpty()) return;
+		if (LOG.isLoggable(INFO))
 			LOG.info("Marking " + unread.size() + " messages read");
 		markMessagesRead(Collections.unmodifiableList(unread));
 	}
@@ -299,12 +299,12 @@ OnClickListener, OnItemClickListener {
 			public void run() {
 				try {
 					long now = System.currentTimeMillis();
-					for(MessageId m : unread) db.setReadFlag(m, true);
+					for (MessageId m : unread) db.setReadFlag(m, true);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Marking read took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -312,17 +312,17 @@ OnClickListener, OnItemClickListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof MessageAddedEvent) {
-			if(((MessageAddedEvent) e).getGroup().getId().equals(groupId)) {
+		if (e instanceof MessageAddedEvent) {
+			if (((MessageAddedEvent) e).getGroup().getId().equals(groupId)) {
 				LOG.info("Message added, reloading");
 				loadHeaders();
 			}
-		} else if(e instanceof MessageExpiredEvent) {
+		} else if (e instanceof MessageExpiredEvent) {
 			LOG.info("Message expired, reloading");
 			loadHeaders();
-		} else if(e instanceof SubscriptionRemovedEvent) {
+		} else if (e instanceof SubscriptionRemovedEvent) {
 			SubscriptionRemovedEvent s = (SubscriptionRemovedEvent) e;
-			if(s.getGroup().getId().equals(groupId)) {
+			if (s.getGroup().getId().equals(groupId)) {
 				LOG.info("Subscription removed");
 				finishOnUiThread();
 			}
@@ -330,13 +330,13 @@ OnClickListener, OnItemClickListener {
 	}
 
 	public void onClick(View view) {
-		if(view == composeButton) {
+		if (view == composeButton) {
 			Intent i = new Intent(this, WriteGroupPostActivity.class);
 			i.putExtra("briar.GROUP_ID", groupId.getBytes());
 			i.putExtra("briar.GROUP_NAME", group.getName());
 			i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewMessage());
 			startActivity(i);
-		} else if(view == shareButton) {
+		} else if (view == shareButton) {
 			Intent i = new Intent(this, ShareGroupActivity.class);
 			i.putExtra("briar.GROUP_ID", groupId.getBytes());
 			i.putExtra("briar.GROUP_NAME", group.getName());
@@ -348,9 +348,9 @@ OnClickListener, OnItemClickListener {
 		// Don't use an earlier timestamp than the newest message
 		long timestamp = 0;
 		int count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
+		for (int i = 0; i < count; i++) {
 			long t = adapter.getItem(i).getHeader().getTimestamp();
-			if(t > timestamp) timestamp = t;
+			if (t > timestamp) timestamp = t;
 		}
 		return timestamp + 1;
 	}
@@ -367,7 +367,7 @@ OnClickListener, OnItemClickListener {
 		i.putExtra("briar.GROUP_NAME", group.getName());
 		i.putExtra("briar.MESSAGE_ID", item.getId().getBytes());
 		Author author = item.getAuthor();
-		if(author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
+		if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
 		i.putExtra("briar.AUTHOR_STATUS", item.getAuthorStatus().name());
 		i.putExtra("briar.CONTENT_TYPE", item.getContentType());
 		i.putExtra("briar.TIMESTAMP", item.getTimestamp());
diff --git a/briar-android/src/org/briarproject/android/groups/GroupAdapter.java b/briar-android/src/org/briarproject/android/groups/GroupAdapter.java
index 220da0fa2a..b1421400de 100644
--- a/briar-android/src/org/briarproject/android/groups/GroupAdapter.java
+++ b/briar-android/src/org/briarproject/android/groups/GroupAdapter.java
@@ -45,7 +45,7 @@ class GroupAdapter extends ArrayAdapter<GroupItem> {
 		LinearLayout layout = new LinearLayout(ctx);
 		layout.setOrientation(VERTICAL);
 		layout.setGravity(CENTER_HORIZONTAL);
-		if(!header.isRead())
+		if (!header.isRead())
 			layout.setBackgroundColor(res.getColor(R.color.unread_background));
 
 		LinearLayout headerLayout = new LinearLayout(ctx);
@@ -55,7 +55,7 @@ class GroupAdapter extends ArrayAdapter<GroupItem> {
 		AuthorView authorView = new AuthorView(ctx);
 		authorView.setLayoutParams(WRAP_WRAP_1);
 		Author author = header.getAuthor();
-		if(author == null) authorView.init(null, header.getAuthorStatus());
+		if (author == null) authorView.init(null, header.getAuthorStatus());
 		else authorView.init(author.getName(), header.getAuthorStatus());
 		headerLayout.addView(authorView);
 
@@ -66,12 +66,12 @@ class GroupAdapter extends ArrayAdapter<GroupItem> {
 		headerLayout.addView(date);
 		layout.addView(headerLayout);
 
-		if(item.getBody() == null) {
+		if (item.getBody() == null) {
 			TextView ellipsis = new TextView(ctx);
 			ellipsis.setPadding(pad, 0, pad, pad);
 			ellipsis.setText("\u2026");
 			layout.addView(ellipsis);
-		} else if(header.getContentType().equals("text/plain")) {
+		} else if (header.getContentType().equals("text/plain")) {
 			TextView text = new TextView(ctx);
 			text.setPadding(pad, 0, pad, pad);
 			text.setText(StringUtils.fromUtf8(item.getBody()));
diff --git a/briar-android/src/org/briarproject/android/groups/GroupItemComparator.java b/briar-android/src/org/briarproject/android/groups/GroupItemComparator.java
index 858c0b2c59..37558da6b9 100644
--- a/briar-android/src/org/briarproject/android/groups/GroupItemComparator.java
+++ b/briar-android/src/org/briarproject/android/groups/GroupItemComparator.java
@@ -10,8 +10,8 @@ class GroupItemComparator implements Comparator<GroupItem> {
 		// The oldest message comes first
 		long aTime = a.getHeader().getTimestamp();
 		long bTime = b.getHeader().getTimestamp();
-		if(aTime < bTime) return -1;
-		if(aTime > bTime) return 1;
+		if (aTime < bTime) return -1;
+		if (aTime > bTime) return 1;
 		return 0;
 	}
 }
diff --git a/briar-android/src/org/briarproject/android/groups/GroupListActivity.java b/briar-android/src/org/briarproject/android/groups/GroupListActivity.java
index 6258b32de8..869939241f 100644
--- a/briar-android/src/org/briarproject/android/groups/GroupListActivity.java
+++ b/briar-android/src/org/briarproject/android/groups/GroupListActivity.java
@@ -154,20 +154,20 @@ OnCreateContextMenuListener {
 			public void run() {
 				try {
 					long now = System.currentTimeMillis();
-					for(Group g : db.getGroups()) {
+					for (Group g : db.getGroups()) {
 						try {
 							displayHeaders(g, db.getMessageHeaders(g.getId()));
-						} catch(NoSuchSubscriptionException e) {
+						} catch (NoSuchSubscriptionException e) {
 							// Continue
 						}
 					}
 					int available = db.getAvailableGroups().size();
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Full load took " + duration + " ms");
 					displayAvailable(available);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -198,7 +198,7 @@ OnCreateContextMenuListener {
 				loading.setVisibility(GONE);
 				// Remove the old item, if any
 				GroupListItem item = findGroup(id);
-				if(item != null) adapter.remove(item);
+				if (item != null) adapter.remove(item);
 				// Add a new item
 				adapter.add(new GroupListItem(g, headers));
 				adapter.sort(GroupListItemComparator.INSTANCE);
@@ -211,9 +211,9 @@ OnCreateContextMenuListener {
 	private void displayAvailable(final int availableCount) {
 		runOnUiThread(new Runnable() {
 			public void run() {
-				if(adapter.isEmpty()) empty.setVisibility(VISIBLE);
+				if (adapter.isEmpty()) empty.setVisibility(VISIBLE);
 				loading.setVisibility(GONE);
-				if(availableCount == 0) {
+				if (availableCount == 0) {
 					available.setVisibility(GONE);
 				} else {
 					available.setVisibility(VISIBLE);
@@ -227,22 +227,22 @@ OnCreateContextMenuListener {
 
 	private GroupListItem findGroup(GroupId g) {
 		int count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
+		for (int i = 0; i < count; i++) {
 			GroupListItem item = adapter.getItem(i);
-			if(item.getGroup().getId().equals(g)) return item;
+			if (item.getGroup().getId().equals(g)) return item;
 		}
 		return null; // Not found
 	}
 
 	private void selectFirstUnread() {
 		int firstUnread = -1, count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
-			if(adapter.getItem(i).getUnreadCount() > 0) {
+		for (int i = 0; i < count; i++) {
+			if (adapter.getItem(i).getUnreadCount() > 0) {
 				firstUnread = i;
 				break;
 			}
 		}
-		if(firstUnread == -1) list.setSelection(count - 1);
+		if (firstUnread == -1) list.setSelection(count - 1);
 		else list.setSelection(firstUnread);
 	}
 
@@ -253,24 +253,24 @@ OnCreateContextMenuListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof MessageAddedEvent) {
+		if (e instanceof MessageAddedEvent) {
 			Group g = ((MessageAddedEvent) e).getGroup();
-			if(groups.containsKey(g.getId())) {
+			if (groups.containsKey(g.getId())) {
 				LOG.info("Message added, reloading");
 				loadHeaders(g);
 			}
-		} else if(e instanceof MessageExpiredEvent) {
+		} else if (e instanceof MessageExpiredEvent) {
 			LOG.info("Message expired, reloading");
 			loadHeaders();
-		} else if(e instanceof RemoteSubscriptionsUpdatedEvent) {
+		} else if (e instanceof RemoteSubscriptionsUpdatedEvent) {
 			LOG.info("Remote subscriptions changed, reloading");
 			loadAvailable();
-		} else if(e instanceof SubscriptionAddedEvent) {
+		} else if (e instanceof SubscriptionAddedEvent) {
 			LOG.info("Group added, reloading");
 			loadHeaders();
-		} else if(e instanceof SubscriptionRemovedEvent) {
+		} else if (e instanceof SubscriptionRemovedEvent) {
 			Group g = ((SubscriptionRemovedEvent) e).getGroup();
-			if(groups.containsKey(g.getId())) {
+			if (groups.containsKey(g.getId())) {
 				LOG.info("Group removed, reloading");
 				loadHeaders();
 			}
@@ -285,13 +285,13 @@ OnCreateContextMenuListener {
 					Collection<MessageHeader> headers =
 							db.getMessageHeaders(g.getId());
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Partial load took " + duration + " ms");
 					displayHeaders(g, headers);
-				} catch(NoSuchSubscriptionException e) {
+				} catch (NoSuchSubscriptionException e) {
 					removeGroup(g.getId());
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -302,11 +302,11 @@ OnCreateContextMenuListener {
 		runOnUiThread(new Runnable() {
 			public void run() {
 				GroupListItem item = findGroup(g);
-				if(item != null) {
+				if (item != null) {
 					groups.remove(g);
 					adapter.remove(item);
 					adapter.notifyDataSetChanged();
-					if(adapter.isEmpty()) {
+					if (adapter.isEmpty()) {
 						empty.setVisibility(VISIBLE);
 						list.setVisibility(GONE);
 					} else {
@@ -324,11 +324,11 @@ OnCreateContextMenuListener {
 					long now = System.currentTimeMillis();
 					int available = db.getAvailableGroups().size();
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading available took " + duration + " ms");
 					displayAvailable(available);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -336,9 +336,9 @@ OnCreateContextMenuListener {
 	}
 
 	public void onClick(View view) {
-		if(view == available) {
+		if (view == available) {
 			startActivity(new Intent(this, AvailableGroupsActivity.class));
-		} else if(view == newGroupButton) {
+		} else if (view == newGroupButton) {
 			startActivity(new Intent(this, CreateGroupActivity.class));
 		}
 	}
@@ -361,7 +361,7 @@ OnCreateContextMenuListener {
 
 	@Override
 	public boolean onContextItemSelected(MenuItem menuItem) {
-		if(menuItem.getItemId() == MENU_ITEM_UNSUBSCRIBE) {
+		if (menuItem.getItemId() == MENU_ITEM_UNSUBSCRIBE) {
 			ContextMenuInfo info = menuItem.getMenuInfo();
 			int position = ((AdapterContextMenuInfo) info).position;
 			GroupListItem item = adapter.getItem(position);
@@ -379,10 +379,10 @@ OnCreateContextMenuListener {
 					long now = System.currentTimeMillis();
 					db.removeGroup(g);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Removing group took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/groups/GroupListAdapter.java b/briar-android/src/org/briarproject/android/groups/GroupListAdapter.java
index b9018350f8..bceebb5e77 100644
--- a/briar-android/src/org/briarproject/android/groups/GroupListAdapter.java
+++ b/briar-android/src/org/briarproject/android/groups/GroupListAdapter.java
@@ -37,7 +37,7 @@ class GroupListAdapter extends ArrayAdapter<GroupListItem> {
 		LinearLayout layout = new LinearLayout(ctx);
 		layout.setOrientation(HORIZONTAL);
 		int unread = item.getUnreadCount();
-		if(unread > 0)
+		if (unread > 0)
 			layout.setBackgroundColor(res.getColor(R.color.unread_background));
 
 		TextView name = new TextView(ctx);
@@ -47,11 +47,11 @@ class GroupListAdapter extends ArrayAdapter<GroupListItem> {
 		name.setEllipsize(END);
 		name.setPadding(pad, pad, pad, pad);
 		String groupName = item.getGroup().getName();
-		if(unread > 0) name.setText(groupName + " (" + unread + ")");
+		if (unread > 0) name.setText(groupName + " (" + unread + ")");
 		else name.setText(groupName);
 		layout.addView(name);
 
-		if(item.isEmpty()) {
+		if (item.isEmpty()) {
 			TextView noPosts = new TextView(ctx);
 			noPosts.setPadding(pad, 0, pad, pad);
 			noPosts.setTextColor(res.getColor(R.color.no_posts));
diff --git a/briar-android/src/org/briarproject/android/groups/GroupListItem.java b/briar-android/src/org/briarproject/android/groups/GroupListItem.java
index 20f9c7a3ff..4b26d33b4a 100644
--- a/briar-android/src/org/briarproject/android/groups/GroupListItem.java
+++ b/briar-android/src/org/briarproject/android/groups/GroupListItem.java
@@ -17,7 +17,7 @@ class GroupListItem {
 	GroupListItem(Group group, Collection<MessageHeader> headers) {
 		this.group = group;
 		empty = headers.isEmpty();
-		if(empty) {
+		if (empty) {
 			authorName = null;
 			contentType = null;
 			timestamp = 0;
@@ -26,15 +26,15 @@ class GroupListItem {
 			MessageHeader newest = null;
 			long timestamp = 0;
 			int unread = 0;
-			for(MessageHeader h : headers) {
-				if(h.getTimestamp() > timestamp) {
+			for (MessageHeader h : headers) {
+				if (h.getTimestamp() > timestamp) {
 					timestamp = h.getTimestamp();
 					newest = h;
 				}
-				if(!h.isRead()) unread++;
+				if (!h.isRead()) unread++;
 			}
 			Author a = newest.getAuthor();
-			if(a == null) authorName = null;
+			if (a == null) authorName = null;
 			else authorName = a.getName();
 			contentType = newest.getContentType();
 			this.timestamp = newest.getTimestamp();
diff --git a/briar-android/src/org/briarproject/android/groups/GroupListItemComparator.java b/briar-android/src/org/briarproject/android/groups/GroupListItemComparator.java
index 7943ea1dff..7d179a7749 100644
--- a/briar-android/src/org/briarproject/android/groups/GroupListItemComparator.java
+++ b/briar-android/src/org/briarproject/android/groups/GroupListItemComparator.java
@@ -8,11 +8,11 @@ class GroupListItemComparator implements Comparator<GroupListItem> {
 			new GroupListItemComparator();
 
 	public int compare(GroupListItem a, GroupListItem b) {
-		if(a == b) return 0;
+		if (a == b) return 0;
 		// The item with the newest message comes first
 		long aTime = a.getTimestamp(), bTime = b.getTimestamp();
-		if(aTime > bTime) return -1;
-		if(aTime < bTime) return 1;
+		if (aTime > bTime) return -1;
+		if (aTime < bTime) return 1;
 		// Break ties by group name
 		String aName = a.getGroup().getName();
 		String bName = b.getGroup().getName();
diff --git a/briar-android/src/org/briarproject/android/groups/NoContactsDialog.java b/briar-android/src/org/briarproject/android/groups/NoContactsDialog.java
index 7da8b7789a..4ca0b6ede4 100644
--- a/briar-android/src/org/briarproject/android/groups/NoContactsDialog.java
+++ b/briar-android/src/org/briarproject/android/groups/NoContactsDialog.java
@@ -16,7 +16,7 @@ public class NoContactsDialog {
 	}
 
 	public Dialog build(Context ctx) {
-		if(listener == null) throw new IllegalStateException();
+		if (listener == null) throw new IllegalStateException();
 		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
 		builder.setMessage(R.string.no_contacts_prompt);
 		builder.setPositiveButton(R.string.add_button,
diff --git a/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java b/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java
index 25a0a3d05d..d97d6e88d0 100644
--- a/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java
+++ b/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java
@@ -66,25 +66,25 @@ implements OnClickListener {
 
 		Intent i = getIntent();
 		byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		groupId = new GroupId(b);
 		groupName = i.getStringExtra("briar.GROUP_NAME");
-		if(groupName == null) throw new IllegalStateException();
+		if (groupName == null) throw new IllegalStateException();
 		setTitle(groupName);
 		b = i.getByteArrayExtra("briar.MESSAGE_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		messageId = new MessageId(b);
 		String contentType = i.getStringExtra("briar.CONTENT_TYPE");
-		if(contentType == null) throw new IllegalStateException();
+		if (contentType == null) throw new IllegalStateException();
 		timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
-		if(timestamp == -1) throw new IllegalStateException();
+		if (timestamp == -1) throw new IllegalStateException();
 		minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
-		if(minTimestamp == -1) throw new IllegalStateException();
+		if (minTimestamp == -1) throw new IllegalStateException();
 		position = i.getIntExtra("briar.POSITION", -1);
-		if(position == -1) throw new IllegalStateException();
+		if (position == -1) throw new IllegalStateException();
 		String authorName = i.getStringExtra("briar.AUTHOR_NAME");
 		String s = i.getStringExtra("briar.AUTHOR_STATUS");
-		if(s == null) throw new IllegalStateException();
+		if (s == null) throw new IllegalStateException();
 		Author.Status authorStatus = Author.Status.valueOf(s);
 
 		LinearLayout layout = new LinearLayout(this);
@@ -115,7 +115,7 @@ implements OnClickListener {
 		header.addView(date);
 		message.addView(header);
 
-		if(contentType.equals("text/plain")) {
+		if (contentType.equals("text/plain")) {
 			// Load and display the message body
 			content = new TextView(this);
 			content.setPadding(pad, 0, pad, pad);
@@ -161,7 +161,7 @@ implements OnClickListener {
 	@Override
 	public void onPause() {
 		super.onPause();
-		if(isFinishing()) markMessageRead();
+		if (isFinishing()) markMessageRead();
 	}
 
 	private void markMessageRead() {
@@ -171,10 +171,10 @@ implements OnClickListener {
 					long now = System.currentTimeMillis();
 					db.setReadFlag(messageId, true);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Marking read took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -188,13 +188,13 @@ implements OnClickListener {
 					long now = System.currentTimeMillis();
 					byte[] body = db.getMessageBody(messageId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading message took " + duration + " ms");
 					displayMessageBody(StringUtils.fromUtf8(body));
-				} catch(NoSuchMessageException e) {
+				} catch (NoSuchMessageException e) {
 					finishOnUiThread();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -210,17 +210,17 @@ implements OnClickListener {
 	}
 
 	public void onClick(View view) {
-		if(view == prevButton) {
+		if (view == prevButton) {
 			Intent i = new Intent();
 			i.putExtra("briar.POSITION", position - 1);
 			setResult(RESULT_PREV_NEXT, i);
 			finish();
-		} else if(view == nextButton) {
+		} else if (view == nextButton) {
 			Intent i = new Intent();
 			i.putExtra("briar.POSITION", position + 1);
 			setResult(RESULT_PREV_NEXT, i);
 			finish();
-		} else if(view == replyButton) {
+		} else if (view == replyButton) {
 			Intent i = new Intent(this, WriteGroupPostActivity.class);
 			i.putExtra("briar.GROUP_ID", groupId.getBytes());
 			i.putExtra("briar.GROUP_NAME", groupName);
diff --git a/briar-android/src/org/briarproject/android/groups/ShareGroupActivity.java b/briar-android/src/org/briarproject/android/groups/ShareGroupActivity.java
index b0eed58999..e926614a28 100644
--- a/briar-android/src/org/briarproject/android/groups/ShareGroupActivity.java
+++ b/briar-android/src/org/briarproject/android/groups/ShareGroupActivity.java
@@ -62,10 +62,10 @@ SelectContactsDialog.Listener {
 
 		Intent i = getIntent();
 		byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		groupId = new GroupId(b);
 		groupName = i.getStringExtra("briar.GROUP_NAME");
-		if(groupName == null) throw new IllegalStateException();
+		if (groupName == null) throw new IllegalStateException();
 		setTitle(groupName);
 
 		LinearLayout layout = new LinearLayout(this);
@@ -109,14 +109,14 @@ SelectContactsDialog.Listener {
 	}
 
 	public void onClick(View view) {
-		if(view == shareWithAll) {
+		if (view == shareWithAll) {
 			changed = true;
-		} else if(view == shareWithSome) {
+		} else if (view == shareWithSome) {
 			changed = true;
-			if(contacts == null) loadVisibility();
+			if (contacts == null) loadVisibility();
 			else displayVisibility();
-		} else if(view == shareButton) {
-			if(changed) {
+		} else if (view == shareButton) {
+			if (changed) {
 				// Replace the button with a progress bar
 				shareButton.setVisibility(GONE);
 				progress.setVisibility(VISIBLE);
@@ -136,11 +136,11 @@ SelectContactsDialog.Listener {
 					contacts = db.getContacts();
 					selected = db.getVisibility(groupId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Load took " + duration + " ms");
 					displayVisibility();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -150,7 +150,7 @@ SelectContactsDialog.Listener {
 	private void displayVisibility() {
 		runOnUiThread(new Runnable() {
 			public void run() {
-				if(contacts.isEmpty()) {
+				if (contacts.isEmpty()) {
 					NoContactsDialog builder = new NoContactsDialog();
 					builder.setListener(ShareGroupActivity.this);
 					builder.build(ShareGroupActivity.this).show();
@@ -171,12 +171,12 @@ SelectContactsDialog.Listener {
 				try {
 					long now = System.currentTimeMillis();
 					db.setVisibleToAll(groupId, all);
-					if(!all) db.setVisibility(groupId, selected);
+					if (!all) db.setVisibility(groupId, selected);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Update took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 				finishOnUiThread();
diff --git a/briar-android/src/org/briarproject/android/groups/WriteGroupPostActivity.java b/briar-android/src/org/briarproject/android/groups/WriteGroupPostActivity.java
index c2c3bea20f..ff5c2c8a20 100644
--- a/briar-android/src/org/briarproject/android/groups/WriteGroupPostActivity.java
+++ b/briar-android/src/org/briarproject/android/groups/WriteGroupPostActivity.java
@@ -89,19 +89,19 @@ implements OnItemSelectedListener, OnClickListener {
 
 		Intent i = getIntent();
 		byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
-		if(b == null) throw new IllegalStateException();
+		if (b == null) throw new IllegalStateException();
 		groupId = new GroupId(b);
 		String groupName = i.getStringExtra("briar.GROUP_NAME");
-		if(groupName == null) throw new IllegalStateException();
+		if (groupName == null) throw new IllegalStateException();
 		setTitle(groupName);
 		minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
-		if(minTimestamp == -1) throw new IllegalStateException();
+		if (minTimestamp == -1) throw new IllegalStateException();
 		b = i.getByteArrayExtra("briar.PARENT_ID");
-		if(b != null) parentId = new MessageId(b);
+		if (b != null) parentId = new MessageId(b);
 
-		if(state != null) {
+		if (state != null) {
 			b = state.getByteArray("briar.LOCAL_AUTHOR_ID");
-			if(b != null) localAuthorId = new AuthorId(b);
+			if (b != null) localAuthorId = new AuthorId(b);
 		}
 
 		LinearLayout layout = new LinearLayout(this);
@@ -169,11 +169,11 @@ implements OnItemSelectedListener, OnClickListener {
 					Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
 					group = db.getGroup(groupId);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Load took " + duration + " ms");
 					displayAuthorsAndGroup(localAuthors);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -184,18 +184,18 @@ implements OnItemSelectedListener, OnClickListener {
 			final Collection<LocalAuthor> localAuthors) {
 		runOnUiThread(new Runnable() {
 			public void run() {
-				if(localAuthors.isEmpty()) throw new IllegalStateException();
+				if (localAuthors.isEmpty()) throw new IllegalStateException();
 				adapter.clear();
-				for(LocalAuthor a : localAuthors)
+				for (LocalAuthor a : localAuthors)
 					adapter.add(new LocalAuthorItem(a));
 				adapter.sort(LocalAuthorItemComparator.INSTANCE);
 				adapter.notifyDataSetChanged();
 				int count = adapter.getCount();
-				for(int i = 0; i < count; i++) {
+				for (int i = 0; i < count; i++) {
 					LocalAuthorItem item = adapter.getItem(i);
-					if(item == LocalAuthorItem.ANONYMOUS) continue;
-					if(item == LocalAuthorItem.NEW) continue;
-					if(item.getLocalAuthor().getId().equals(localAuthorId)) {
+					if (item == LocalAuthorItem.ANONYMOUS) continue;
+					if (item == LocalAuthorItem.NEW) continue;
+					if (item.getLocalAuthor().getId().equals(localAuthorId)) {
 						localAuthor = item.getLocalAuthor();
 						spinner.setSelection(i);
 						break;
@@ -210,7 +210,7 @@ implements OnItemSelectedListener, OnClickListener {
 	@Override
 	public void onSaveInstanceState(Bundle state) {
 		super.onSaveInstanceState(state);
-		if(localAuthorId != null) {
+		if (localAuthorId != null) {
 			byte[] b =  localAuthorId.getBytes();
 			state.putByteArray("briar.LOCAL_AUTHOR_ID", b);
 		}
@@ -219,9 +219,9 @@ implements OnItemSelectedListener, OnClickListener {
 	@Override
 	protected void onActivityResult(int request, int result, Intent data) {
 		super.onActivityResult(request, result, data);
-		if(request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
+		if (request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
 			byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
-			if(b == null) throw new IllegalStateException();
+			if (b == null) throw new IllegalStateException();
 			localAuthorId = new AuthorId(b);
 			loadAuthorsAndGroup();
 		}
@@ -230,10 +230,10 @@ implements OnItemSelectedListener, OnClickListener {
 	public void onItemSelected(AdapterView<?> parent, View view, int position,
 			long id) {
 		LocalAuthorItem item = adapter.getItem(position);
-		if(item == LocalAuthorItem.ANONYMOUS) {
+		if (item == LocalAuthorItem.ANONYMOUS) {
 			localAuthor = null;
 			localAuthorId = null;
-		} else if(item == LocalAuthorItem.NEW) {
+		} else if (item == LocalAuthorItem.NEW) {
 			localAuthor = null;
 			localAuthorId = null;
 			Intent i = new Intent(this, CreateIdentityActivity.class);
@@ -250,9 +250,9 @@ implements OnItemSelectedListener, OnClickListener {
 	}
 
 	public void onClick(View view) {
-		if(group == null) throw new IllegalStateException();
+		if (group == null) throw new IllegalStateException();
 		String message = content.getText().toString();
-		if(message.equals("")) return;
+		if (message.equals("")) return;
 		createMessage(StringUtils.toUtf8(message));
 		Toast.makeText(this, R.string.post_sent_toast, LENGTH_LONG).show();
 		finish();
@@ -266,7 +266,7 @@ implements OnItemSelectedListener, OnClickListener {
 				timestamp = Math.max(timestamp, minTimestamp);
 				Message m;
 				try {
-					if(localAuthor == null) {
+					if (localAuthor == null) {
 						m = messageFactory.createAnonymousMessage(parentId,
 								group, "text/plain", timestamp, body);
 					} else {
@@ -277,9 +277,9 @@ implements OnItemSelectedListener, OnClickListener {
 								group, localAuthor, authorKey, "text/plain",
 								timestamp, body);
 					}
-				} catch(GeneralSecurityException e) {
+				} catch (GeneralSecurityException e) {
 					throw new RuntimeException(e);
-				} catch(IOException e) {
+				} catch (IOException e) {
 					throw new RuntimeException(e);
 				}
 				storeMessage(m);
@@ -294,10 +294,10 @@ implements OnItemSelectedListener, OnClickListener {
 					long now = System.currentTimeMillis();
 					db.addLocalMessage(m);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Storing message took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java b/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java
index ded8912dbc..458b194d98 100644
--- a/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java
+++ b/briar-android/src/org/briarproject/android/identity/CreateIdentityActivity.java
@@ -113,7 +113,7 @@ implements OnEditorActionListener, OnClickListener {
 	}
 
 	private void enableOrDisableCreateButton() {
-		if(progress == null) return; // Not created yet
+		if (progress == null) return; // Not created yet
 		createIdentityButton.setEnabled(validateNickname());
 	}
 
@@ -125,7 +125,7 @@ implements OnEditorActionListener, OnClickListener {
 	private boolean validateNickname() {
 		String nickname = nicknameEntry.getText().toString();
 		int length = StringUtils.toUtf8(nickname).length;
-		if(length > MAX_AUTHOR_NAME_LENGTH) {
+		if (length > MAX_AUTHOR_NAME_LENGTH) {
 			feedback.setText(R.string.name_too_long);
 			return false;
 		}
@@ -135,7 +135,7 @@ implements OnEditorActionListener, OnClickListener {
 
 	public void onClick(View view) {
 		hideSoftKeyboard();
-		if(!validateNickname()) return;
+		if (!validateNickname()) return;
 		// Replace the button with a progress bar
 		createIdentityButton.setVisibility(GONE);
 		progress.setVisibility(VISIBLE);
@@ -160,10 +160,10 @@ implements OnEditorActionListener, OnClickListener {
 					long now = System.currentTimeMillis();
 					db.addLocalAuthor(a);
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Storing author took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 				setResultAndFinish(a);
diff --git a/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java b/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java
index 1b37470d6f..634d062e4c 100644
--- a/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java
+++ b/briar-android/src/org/briarproject/android/identity/LocalAuthorItemComparator.java
@@ -11,18 +11,18 @@ public class LocalAuthorItemComparator implements Comparator<LocalAuthorItem> {
 			new LocalAuthorItemComparator();
 
 	public int compare(LocalAuthorItem a, LocalAuthorItem b) {
-		if(a == b) return 0;
+		if (a == b) return 0;
 		// NEW comes after everything else
-		if(a == NEW) return 1;
-		if(b == NEW) return -1;
+		if (a == NEW) return 1;
+		if (b == NEW) return -1;
 		// ANONYMOUS comes after everything else except NEW
-		if(a == ANONYMOUS) return 1;
-		if(b == ANONYMOUS) return -1;
+		if (a == ANONYMOUS) return 1;
+		if (b == ANONYMOUS) return -1;
 		// Sort items in order of creation, so the oldest item is the default
 		long aCreated = a.getLocalAuthor().getTimeCreated();
 		long bCreated = b.getLocalAuthor().getTimeCreated();
-		if(aCreated < bCreated) return -1;
-		if(aCreated > bCreated) return 1;
+		if (aCreated < bCreated) return -1;
+		if (aCreated > bCreated) return 1;
 		return 0;
 	}
 }
diff --git a/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java b/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java
index 57a8e019aa..7fc331edf9 100644
--- a/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java
+++ b/briar-android/src/org/briarproject/android/identity/LocalAuthorSpinnerAdapter.java
@@ -40,7 +40,7 @@ implements SpinnerAdapter {
 	}
 
 	public int getCount() {
-		if(list.isEmpty()) return 0;
+		if (list.isEmpty()) return 0;
 		return includeAnonymous ? list.size() + 2 : list.size() + 1;
 	}
 
@@ -54,19 +54,19 @@ implements SpinnerAdapter {
 		int pad = LayoutUtils.getPadding(ctx);
 		name.setPadding(pad, pad, pad, pad);
 		LocalAuthorItem item = getItem(position);
-		if(item == ANONYMOUS) name.setText(R.string.anonymous);
-		else if(item == NEW) name.setText(R.string.new_identity_item);
+		if (item == ANONYMOUS) name.setText(R.string.anonymous);
+		else if (item == NEW) name.setText(R.string.new_identity_item);
 		else name.setText(item.getLocalAuthor().getName());
 		return name;
 	}
 
 	public LocalAuthorItem getItem(int position) {
-		if(includeAnonymous) {
-			if(position == list.size()) return ANONYMOUS;
-			if(position == list.size() + 1) return NEW;
+		if (includeAnonymous) {
+			if (position == list.size()) return ANONYMOUS;
+			if (position == list.size() + 1) return NEW;
 			return list.get(position);
 		} else {
-			if(position == list.size()) return NEW;
+			if (position == list.size()) return NEW;
 			return list.get(position);
 		}
 	}
@@ -81,8 +81,8 @@ implements SpinnerAdapter {
 		name.setSingleLine();
 		name.setEllipsize(END);
 		LocalAuthorItem item = getItem(position);
-		if(item == ANONYMOUS) name.setText(R.string.anonymous);
-		else if(item == NEW) name.setText(R.string.new_identity_item);
+		if (item == ANONYMOUS) name.setText(R.string.anonymous);
+		else if (item == NEW) name.setText(R.string.new_identity_item);
 		else name.setText(item.getLocalAuthor().getName());
 		return name;
 	}
diff --git a/briar-android/src/org/briarproject/android/invitation/AddContactActivity.java b/briar-android/src/org/briarproject/android/invitation/AddContactActivity.java
index 60c052051a..eb0a52e9da 100644
--- a/briar-android/src/org/briarproject/android/invitation/AddContactActivity.java
+++ b/briar-android/src/org/briarproject/android/invitation/AddContactActivity.java
@@ -60,34 +60,34 @@ implements InvitationListener {
 	@Override
 	public void onCreate(Bundle state) {
 		super.onCreate(state);
-		if(state == null) {
+		if (state == null) {
 			// This is a new activity
 			setView(new ChooseIdentityView(this));
 		} else {
 			// Restore the activity's state
 			byte[] b = state.getByteArray("briar.LOCAL_AUTHOR_ID");
-			if(b != null) localAuthorId = new AuthorId(b);
+			if (b != null) localAuthorId = new AuthorId(b);
 			taskHandle = state.getLong("briar.TASK_HANDLE", -1);
 			task = referenceManager.getReference(taskHandle,
 					InvitationTask.class);
-			if(task == null) {
+			if (task == null) {
 				// No background task - we must be in an initial or final state
 				localInvitationCode = state.getInt("briar.LOCAL_CODE");
 				remoteInvitationCode = state.getInt("briar.REMOTE_CODE");
 				connectionFailed = state.getBoolean("briar.FAILED");
 				contactName = state.getString("briar.CONTACT_NAME");
-				if(contactName != null) {
+				if (contactName != null) {
 					localCompared = remoteCompared = true;
 					localMatched = remoteMatched = true;
 				}
 				// Set the appropriate view for the state
-				if(localInvitationCode == -1) {
+				if (localInvitationCode == -1) {
 					setView(new ChooseIdentityView(this));
-				} else if(remoteInvitationCode == -1) {
+				} else if (remoteInvitationCode == -1) {
 					setView(new InvitationCodeView(this));
-				} else if(connectionFailed) {
+				} else if (connectionFailed) {
 					setView(new ConnectionFailedView(this));
-				} else if(contactName == null) {
+				} else if (contactName == null) {
 					setView(new CodesDoNotMatchView(this));
 				} else {
 					showToastAndFinish();
@@ -108,22 +108,22 @@ implements InvitationListener {
 				remoteMatched = s.getRemoteMatched();
 				contactName = s.getContactName();
 				// Set the appropriate view for the state
-				if(localInvitationCode == -1) {
+				if (localInvitationCode == -1) {
 					setView(new ChooseIdentityView(this));
-				} else if(remoteInvitationCode == -1) {
+				} else if (remoteInvitationCode == -1) {
 					setView(new InvitationCodeView(this));
-				} else if(connectionFailed) {
+				} else if (connectionFailed) {
 					setView(new ConnectionFailedView(this));
-				} else if(connected && localConfirmationCode == -1) {
+				} else if (connected && localConfirmationCode == -1) {
 					setView(new ConnectedView(this));
-				} else if(localConfirmationCode == -1) {
+				} else if (localConfirmationCode == -1) {
 					setView(new ConnectionView(this));
-				} else if(!localCompared) {
+				} else if (!localCompared) {
 					setView(new ConfirmationCodeView(this));
-				} else if(!remoteCompared) {
+				} else if (!remoteCompared) {
 					setView(new WaitForContactView(this));
-				} else if(localMatched && remoteMatched) {
-					if(contactName == null) {
+				} else if (localMatched && remoteMatched) {
+					if (contactName == null) {
 						setView(new ContactDetailsView(this));
 					} else {
 						showToastAndFinish();
@@ -135,7 +135,7 @@ implements InvitationListener {
 			}
 		}
 		BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-		if(adapter != null) bluetoothWasEnabled = adapter.isEnabled();
+		if (adapter != null) bluetoothWasEnabled = adapter.isEnabled();
 	}
 
 	private void showToastAndFinish() {
@@ -159,11 +159,11 @@ implements InvitationListener {
 					long now = System.currentTimeMillis();
 					TransportConfig c = db.getConfig(new TransportId("bt"));
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading setting took " + duration + " ms");
 					enableBluetooth = c.getBoolean("enable", true);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -173,7 +173,7 @@ implements InvitationListener {
 	@Override
 	public void onSaveInstanceState(Bundle state) {
 		super.onSaveInstanceState(state);
-		if(localAuthorId != null) {
+		if (localAuthorId != null) {
 			byte[] b = localAuthorId.getBytes();
 			state.putByteArray("briar.LOCAL_AUTHOR_ID", b);
 		}
@@ -181,26 +181,26 @@ implements InvitationListener {
 		state.putInt("briar.REMOTE_CODE", remoteInvitationCode);
 		state.putBoolean("briar.FAILED", connectionFailed);
 		state.putString("briar.CONTACT_NAME", contactName);
-		if(task != null) state.putLong("briar.TASK_HANDLE", taskHandle);
+		if (task != null) state.putLong("briar.TASK_HANDLE", taskHandle);
 	}
 
 	@Override
 	public void onDestroy() {
 		super.onDestroy();
-		if(task != null) task.removeListener(this);
-		if(!bluetoothWasEnabled && !enableBluetooth) {
+		if (task != null) task.removeListener(this);
+		if (!bluetoothWasEnabled && !enableBluetooth) {
 			BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-			if(adapter != null) adapter.disable();
+			if (adapter != null) adapter.disable();
 		}
 	}
 
 	@Override
 	public void onActivityResult(int request, int result, Intent data) {
-		if(request == REQUEST_BLUETOOTH) {
-			if(result != RESULT_CANCELED) reset(new InvitationCodeView(this));
-		} else if(request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
+		if (request == REQUEST_BLUETOOTH) {
+			if (result != RESULT_CANCELED) reset(new InvitationCodeView(this));
+		} else if (request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
 			byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
-			if(b == null) throw new IllegalStateException();
+			if (b == null) throw new IllegalStateException();
 			localAuthorId = new AuthorId(b);
 			setView(new ChooseIdentityView(this));
 		}
@@ -232,11 +232,11 @@ implements InvitationListener {
 					long now = System.currentTimeMillis();
 					Collection<LocalAuthor> authors = db.getLocalAuthors();
 					long duration = System.currentTimeMillis() - now;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Loading authors took " + duration + " ms");
 					displayLocalAuthors(authors);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
@@ -248,7 +248,7 @@ implements InvitationListener {
 		runOnUiThread(new Runnable() {
 			public void run() {
 				AddContactView view = AddContactActivity.this.view;
-				if(view instanceof ChooseIdentityView)
+				if (view instanceof ChooseIdentityView)
 					((ChooseIdentityView) view).displayLocalAuthors(authors);
 			}
 		});
@@ -263,7 +263,7 @@ implements InvitationListener {
 	}
 
 	int getLocalInvitationCode() {
-		if(localInvitationCode == -1)
+		if (localInvitationCode == -1)
 			localInvitationCode = crypto.generateInvitationCode();
 		return localInvitationCode;
 	}
@@ -273,8 +273,8 @@ implements InvitationListener {
 	}
 
 	void remoteInvitationCodeEntered(int code) {
-		if(localAuthorId == null) throw new IllegalStateException();
-		if(localInvitationCode == -1) throw new IllegalStateException();
+		if (localAuthorId == null) throw new IllegalStateException();
+		if (localInvitationCode == -1) throw new IllegalStateException();
 		remoteInvitationCode = code;
 		setView(new ConnectionView(this));
 		task = invitationTaskFactory.createTask(localAuthorId,
@@ -293,10 +293,10 @@ implements InvitationListener {
 
 	void remoteConfirmationCodeEntered(int code) {
 		localCompared = true;
-		if(code == remoteConfirmationCode) {
+		if (code == remoteConfirmationCode) {
 			localMatched = true;
-			if(remoteMatched) setView(new ContactDetailsView(this));
-			else if(remoteCompared) setView(new CodesDoNotMatchView(this));
+			if (remoteMatched) setView(new ContactDetailsView(this));
+			else if (remoteCompared) setView(new CodesDoNotMatchView(this));
 			else setView(new WaitForContactView(this));
 			task.localConfirmationSucceeded();
 		} else {
@@ -353,7 +353,7 @@ implements InvitationListener {
 			public void run() {
 				remoteCompared = true;
 				remoteMatched = true;
-				if(localMatched)
+				if (localMatched)
 					setView(new ContactDetailsView(AddContactActivity.this));
 			}
 		});
@@ -364,7 +364,7 @@ implements InvitationListener {
 			public void run() {
 				remoteCompared = true;
 				remoteMatched = false;
-				if(localMatched)
+				if (localMatched)
 					setView(new CodesDoNotMatchView(AddContactActivity.this));
 			}
 		});
diff --git a/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java b/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java
index b81858db46..5ecd1898fa 100644
--- a/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java
+++ b/briar-android/src/org/briarproject/android/invitation/ChooseIdentityView.java
@@ -80,17 +80,17 @@ implements OnItemSelectedListener, OnClickListener {
 	// FIXME: The interaction between views and the container is horrible
 	void displayLocalAuthors(Collection<LocalAuthor> authors) {
 		adapter.clear();
-		for(LocalAuthor a : authors) adapter.add(new LocalAuthorItem(a));
+		for (LocalAuthor a : authors) adapter.add(new LocalAuthorItem(a));
 		adapter.sort(LocalAuthorItemComparator.INSTANCE);
 		adapter.notifyDataSetChanged();
 		// If a local author has been selected, select it again
 		AuthorId localAuthorId = container.getLocalAuthorId();
-		if(localAuthorId == null) return;
+		if (localAuthorId == null) return;
 		int count = adapter.getCount();
-		for(int i = 0; i < count; i++) {
+		for (int i = 0; i < count; i++) {
 			LocalAuthorItem item = adapter.getItem(i);
-			if(item == NEW) continue;
-			if(item.getLocalAuthor().getId().equals(localAuthorId)) {
+			if (item == NEW) continue;
+			if (item.getLocalAuthor().getId().equals(localAuthorId)) {
 				spinner.setSelection(i);
 				return;
 			}
@@ -100,7 +100,7 @@ implements OnItemSelectedListener, OnClickListener {
 	public void onItemSelected(AdapterView<?> parent, View view, int position,
 			long id) {
 		LocalAuthorItem item = adapter.getItem(position);
-		if(item == NEW) {
+		if (item == NEW) {
 			container.setLocalAuthorId(null);
 			Intent i = new Intent(container, CreateIdentityActivity.class);
 			container.startActivityForResult(i, REQUEST_CREATE_IDENTITY);
diff --git a/briar-android/src/org/briarproject/android/invitation/CodeEntryView.java b/briar-android/src/org/briarproject/android/invitation/CodeEntryView.java
index b09ef75049..d15bfdab37 100644
--- a/briar-android/src/org/briarproject/android/invitation/CodeEntryView.java
+++ b/briar-android/src/org/briarproject/android/invitation/CodeEntryView.java
@@ -55,7 +55,7 @@ implements OnEditorActionListener, OnClickListener {
 			@Override
 			protected void onTextChanged(CharSequence text, int start,
 					int lengthBefore, int lengthAfter) {
-				if(continueButton != null)
+				if (continueButton != null)
 					continueButton.setEnabled(getText().length() == 6);
 			}
 		};
@@ -78,12 +78,12 @@ implements OnEditorActionListener, OnClickListener {
 	}
 
 	public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
-		if(!validateAndReturnCode()) codeEntry.setText("");
+		if (!validateAndReturnCode()) codeEntry.setText("");
 		return true;
 	}
 
 	public void onClick(View view) {
-		if(!validateAndReturnCode()) codeEntry.setText("");
+		if (!validateAndReturnCode()) codeEntry.setText("");
 	}
 
 	private boolean validateAndReturnCode() {
@@ -91,7 +91,7 @@ implements OnEditorActionListener, OnClickListener {
 		int remoteCode;
 		try {
 			remoteCode = Integer.parseInt(remoteCodeString);
-		} catch(NumberFormatException e) {
+		} catch (NumberFormatException e) {
 			return false;
 		}
 		// Hide the soft keyboard
diff --git a/briar-android/src/org/briarproject/android/util/AndroidUtils.java b/briar-android/src/org/briarproject/android/util/AndroidUtils.java
index 64e39aee22..4f0ef6327e 100644
--- a/briar-android/src/org/briarproject/android/util/AndroidUtils.java
+++ b/briar-android/src/org/briarproject/android/util/AndroidUtils.java
@@ -14,11 +14,11 @@ public class AndroidUtils {
 	@SuppressWarnings("deprecation")
 	public static Collection<String> getSupportedArchitectures() {
 		List<String> abis = new ArrayList<String>();
-		if(Build.VERSION.SDK_INT >= 21) {
-			for(String abi : Build.SUPPORTED_ABIS) abis.add(abi);
-		} else if(Build.VERSION.SDK_INT >= 8) {
+		if (Build.VERSION.SDK_INT >= 21) {
+			for (String abi : Build.SUPPORTED_ABIS) abis.add(abi);
+		} else if (Build.VERSION.SDK_INT >= 8) {
 			abis.add(Build.CPU_ABI);
-			if(Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
+			if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
 		} else {
 			abis.add(Build.CPU_ABI);
 		}
diff --git a/briar-android/src/org/briarproject/android/util/AuthorView.java b/briar-android/src/org/briarproject/android/util/AuthorView.java
index 40e55ce8ab..b73c7c85cb 100644
--- a/briar-android/src/org/briarproject/android/util/AuthorView.java
+++ b/briar-android/src/org/briarproject/android/util/AuthorView.java
@@ -26,7 +26,7 @@ public class AuthorView extends RelativeLayout {
 		nameView.setSingleLine();
 		nameView.setEllipsize(END);
 		nameView.setPadding(pad, pad, pad, pad);
-		if(name == null) nameView.setText(R.string.anonymous);
+		if (name == null) nameView.setText(R.string.anonymous);
 		else nameView.setText(name);
 		LayoutParams leftOf = CommonLayoutParams.relative();
 		leftOf.addRule(ALIGN_PARENT_LEFT);
diff --git a/briar-android/src/org/briarproject/android/util/StrengthMeter.java b/briar-android/src/org/briarproject/android/util/StrengthMeter.java
index ca3261a8af..8a1507b693 100644
--- a/briar-android/src/org/briarproject/android/util/StrengthMeter.java
+++ b/briar-android/src/org/briarproject/android/util/StrengthMeter.java
@@ -52,12 +52,12 @@ public class StrengthMeter extends ProgressBar {
 	}
 
 	public void setStrength(float strength) {
-		if(strength < 0 || strength > 1) throw new IllegalArgumentException();
+		if (strength < 0 || strength > 1) throw new IllegalArgumentException();
 		int colour;
-		if(strength < WEAK) colour = RED;
-		else if(strength < QUITE_WEAK) colour = ORANGE;
-		else if(strength < QUITE_STRONG) colour = YELLOW;
-		else if(strength < STRONG) colour = LIME;
+		if (strength < WEAK) colour = RED;
+		else if (strength < QUITE_WEAK) colour = ORANGE;
+		else if (strength < QUITE_STRONG) colour = YELLOW;
+		else if (strength < STRONG) colour = LIME;
 		else colour = GREEN;
 		bar.getPaint().setColor(colour);
 		setProgress((int) (strength * MAX));
diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java
index f7afa6739c..a8a18ce2bb 100644
--- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java
+++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java
@@ -115,13 +115,13 @@ class DroidtoothPlugin implements DuplexPlugin {
 					return BluetoothAdapter.getDefaultAdapter();
 				}
 			});
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while getting BluetoothAdapter");
-		} catch(ExecutionException e) {
+		} catch (ExecutionException e) {
 			throw new IOException(e.toString());
 		}
-		if(adapter == null) {
+		if (adapter == null) {
 			LOG.info("Bluetooth is not supported");
 			return false;
 		}
@@ -133,11 +133,11 @@ class DroidtoothPlugin implements DuplexPlugin {
 		receiver = new BluetoothStateReceiver();
 		appContext.registerReceiver(receiver, filter);
 		// If Bluetooth is enabled, bind a socket - otherwise enable it
-		if(adapter.isEnabled()) {
+		if (adapter.isEnabled()) {
 			bind();
-		} else if(callback.getConfig().getBoolean("enable", true)) {
+		} else if (callback.getConfig().getBoolean("enable", true)) {
 			wasDisabled = true;
-			if(adapter.enable()) LOG.info("Enabling Bluetooth");
+			if (adapter.enable()) LOG.info("Enabling Bluetooth");
 			else LOG.info("Could not enable Bluetooth");
 		} else {
 			LOG.info("Not enabling Bluetooth");
@@ -148,8 +148,8 @@ class DroidtoothPlugin implements DuplexPlugin {
 	private void bind() {
 		ioExecutor.execute(new Runnable() {
 			public void run() {
-				if(!isRunning()) return;
-				if(LOG.isLoggable(INFO))
+				if (!isRunning()) return;
+				if (LOG.isLoggable(INFO))
 					LOG.info("Local address " + adapter.getAddress());
 				// Advertise the Bluetooth address to contacts
 				TransportProperties p = new TransportProperties();
@@ -159,13 +159,13 @@ class DroidtoothPlugin implements DuplexPlugin {
 				BluetoothServerSocket ss = null;
 				try {
 					ss = InsecureBluetooth.listen(adapter, "RFCOMM", getUuid());
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					tryToClose(ss);
 					return;
 				}
-				if(!isRunning()) {
+				if (!isRunning()) {
 					tryToClose(ss);
 					return;
 				}
@@ -179,7 +179,7 @@ class DroidtoothPlugin implements DuplexPlugin {
 
 	private UUID getUuid() {
 		String uuid = callback.getLocalProperties().get("uuid");
-		if(uuid == null) {
+		if (uuid == null) {
 			byte[] random = new byte[UUID_BYTES];
 			secureRandom.nextBytes(random);
 			uuid = UUID.nameUUIDFromBytes(random).toString();
@@ -192,23 +192,23 @@ class DroidtoothPlugin implements DuplexPlugin {
 
 	private void tryToClose(BluetoothServerSocket ss) {
 		try {
-			if(ss != null) ss.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (ss != null) ss.close();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	private void acceptContactConnections() {
-		while(isRunning()) {
+		while (isRunning()) {
 			BluetoothSocket s;
 			try {
 				s = socket.accept();
-			} catch(IOException e) {
+			} catch (IOException e) {
 				// This is expected when the socket is closed
-				if(LOG.isLoggable(INFO)) LOG.info(e.toString());
+				if (LOG.isLoggable(INFO)) LOG.info(e.toString());
 				return;
 			}
-			if(LOG.isLoggable(INFO)) {
+			if (LOG.isLoggable(INFO)) {
 				String address = s.getRemoteDevice().getAddress();
 				LOG.info("Connection from " + address);
 			}
@@ -222,11 +222,11 @@ class DroidtoothPlugin implements DuplexPlugin {
 
 	public void stop() {
 		running = false;
-		if(receiver != null) appContext.unregisterReceiver(receiver);
+		if (receiver != null) appContext.unregisterReceiver(receiver);
 		tryToClose(socket);
 		// Disable Bluetooth if we enabled it and it's still enabled
-		if(wasDisabled && adapter.isEnabled()) {
-			if(adapter.disable()) LOG.info("Disabling Bluetooth");
+		if (wasDisabled && adapter.isEnabled()) {
+			if (adapter.disable()) LOG.info("Disabling Bluetooth");
 			else LOG.info("Could not disable Bluetooth");
 		}
 	}
@@ -244,22 +244,22 @@ class DroidtoothPlugin implements DuplexPlugin {
 	}
 
 	public void poll(Collection<ContactId> connected) {
-		if(!isRunning()) return;
+		if (!isRunning()) return;
 		// Try to connect to known devices in parallel
 		Map<ContactId, TransportProperties> remote =
 				callback.getRemoteProperties();
-		for(Entry<ContactId, TransportProperties> e : remote.entrySet()) {
+		for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
 			final ContactId c = e.getKey();
-			if(connected.contains(c)) continue;
+			if (connected.contains(c)) continue;
 			final String address = e.getValue().get("address");
-			if(StringUtils.isNullOrEmpty(address)) continue;
+			if (StringUtils.isNullOrEmpty(address)) continue;
 			final String uuid = e.getValue().get("uuid");
-			if(StringUtils.isNullOrEmpty(uuid)) continue;
+			if (StringUtils.isNullOrEmpty(uuid)) continue;
 			ioExecutor.execute(new Runnable() {
 				public void run() {
-					if(!running) return;
+					if (!running) return;
 					BluetoothSocket s = connect(address, uuid);
-					if(s != null)
+					if (s != null)
 						callback.outgoingConnectionCreated(c, wrapSocket(s));
 				}
 			});
@@ -268,8 +268,8 @@ class DroidtoothPlugin implements DuplexPlugin {
 
 	private BluetoothSocket connect(String address, String uuid) {
 		// Validate the address
-		if(!BluetoothAdapter.checkBluetoothAddress(address)) {
-			if(LOG.isLoggable(WARNING))
+		if (!BluetoothAdapter.checkBluetoothAddress(address)) {
+			if (LOG.isLoggable(WARNING))
 				LOG.warning("Invalid address " + address);
 			return null;
 		}
@@ -277,8 +277,8 @@ class DroidtoothPlugin implements DuplexPlugin {
 		UUID u;
 		try {
 			u = UUID.fromString(uuid);
-		} catch(IllegalArgumentException e) {
-			if(LOG.isLoggable(WARNING)) LOG.warning("Invalid UUID " + uuid);
+		} catch (IllegalArgumentException e) {
+			if (LOG.isLoggable(WARNING)) LOG.warning("Invalid UUID " + uuid);
 			return null;
 		}
 		// Try to connect
@@ -286,12 +286,12 @@ class DroidtoothPlugin implements DuplexPlugin {
 		BluetoothSocket s = null;
 		try {
 			s = InsecureBluetooth.createSocket(d, u);
-			if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + address);
+			if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + address);
 			s.connect();
-			if(LOG.isLoggable(INFO)) LOG.info("Connected to " + address);
+			if (LOG.isLoggable(INFO)) LOG.info("Connected to " + address);
 			return s;
-		} catch(IOException e) {
-			if(LOG.isLoggable(INFO))
+		} catch (IOException e) {
+			if (LOG.isLoggable(INFO))
 				LOG.info("Failed to connect to " + address);
 			tryToClose(s);
 			return null;
@@ -300,22 +300,22 @@ class DroidtoothPlugin implements DuplexPlugin {
 
 	private void tryToClose(BluetoothSocket s) {
 		try {
-			if(s != null) s.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (s != null) s.close();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	public DuplexTransportConnection createConnection(ContactId c) {
-		if(!isRunning()) return null;
+		if (!isRunning()) return null;
 		TransportProperties p = callback.getRemoteProperties().get(c);
-		if(p == null) return null;
+		if (p == null) return null;
 		String address = p.get("address");
-		if(StringUtils.isNullOrEmpty(address)) return null;
+		if (StringUtils.isNullOrEmpty(address)) return null;
 		String uuid = p.get("uuid");
-		if(StringUtils.isNullOrEmpty(uuid)) return null;
+		if (StringUtils.isNullOrEmpty(uuid)) return null;
 		BluetoothSocket s = connect(address, uuid);
-		if(s == null) return null;
+		if (s == null) return null;
 		return new DroidtoothTransportConnection(this, s);
 	}
 
@@ -325,17 +325,17 @@ class DroidtoothPlugin implements DuplexPlugin {
 
 	public DuplexTransportConnection createInvitationConnection(PseudoRandom r,
 			long timeout) {
-		if(!isRunning()) return null;
+		if (!isRunning()) return null;
 		// Use the invitation codes to generate the UUID
 		byte[] b = r.nextBytes(UUID_BYTES);
 		UUID uuid = UUID.nameUUIDFromBytes(b);
-		if(LOG.isLoggable(INFO)) LOG.info("Invitation UUID " + uuid);
+		if (LOG.isLoggable(INFO)) LOG.info("Invitation UUID " + uuid);
 		// Bind a server socket for receiving invitation connections
 		BluetoothServerSocket ss = null;
 		try {
 			ss = InsecureBluetooth.listen(adapter, "RFCOMM", uuid);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			tryToClose(ss);
 			return null;
 		}
@@ -347,8 +347,8 @@ class DroidtoothPlugin implements DuplexPlugin {
 		// Wait for an incoming or outgoing connection
 		try {
 			BluetoothSocket s = socketLatch.waitForReference(timeout);
-			if(s != null) return new DroidtoothTransportConnection(this, s);
-		} catch(InterruptedException e) {
+			if (s != null) return new DroidtoothTransportConnection(this, s);
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while exchanging invitations");
 			Thread.currentThread().interrupt();
 		} finally {
@@ -363,19 +363,19 @@ class DroidtoothPlugin implements DuplexPlugin {
 		@Override
 		public void onReceive(Context ctx, Intent intent) {
 			int state = intent.getIntExtra(EXTRA_STATE, 0);
-			if(state == STATE_ON) {
+			if (state == STATE_ON) {
 				LOG.info("Bluetooth enabled");
 				bind();
-			} else if(state == STATE_OFF) {
+			} else if (state == STATE_OFF) {
 				LOG.info("Bluetooth disabled");
 				tryToClose(socket);
 			}
 			int scanMode = intent.getIntExtra(EXTRA_SCAN_MODE, 0);
-			if(scanMode == SCAN_MODE_NONE) {
+			if (scanMode == SCAN_MODE_NONE) {
 				LOG.info("Scan mode: None");
-			} else if(scanMode == SCAN_MODE_CONNECTABLE) {
+			} else if (scanMode == SCAN_MODE_CONNECTABLE) {
 				LOG.info("Scan mode: Connectable");
-			} else if(scanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
+			} else if (scanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
 				LOG.info("Scan mode: Discoverable");
 			}
 		}
@@ -397,29 +397,29 @@ class DroidtoothPlugin implements DuplexPlugin {
 		@Override
 		public void run() {
 			long end = clock.currentTimeMillis() + timeout;
-			while(!finished(end)) {
+			while (!finished(end)) {
 				// Discover nearby devices
 				LOG.info("Discovering nearby devices");
 				List<String> addresses;
 				try {
 					long now = clock.currentTimeMillis();
 					addresses = discoverDevices(end - now);
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.warning("Interrupted while discovering devices");
 					Thread.currentThread().interrupt();
 					return;
 				}
-				if(addresses.isEmpty()) {
+				if (addresses.isEmpty()) {
 					LOG.info("No devices discovered");
 					continue;
 				}
 				// Connect to any device with the right UUID
-				for(String address : addresses) {
-					if(finished(end)) return;
+				for (String address : addresses) {
+					if (finished(end)) return;
 					BluetoothSocket s = connect(address, uuid);
-					if(s != null) {
+					if (s != null) {
 						LOG.info("Outgoing connection");
-						if(!socketLatch.set(s)) {
+						if (!socketLatch.set(s)) {
 							LOG.info("Closing redundant connection");
 							tryToClose(s);
 						}
@@ -455,13 +455,13 @@ class DroidtoothPlugin implements DuplexPlugin {
 		@Override
 		public void onReceive(Context ctx, Intent intent) {
 			String action = intent.getAction();
-			if(action.equals(DISCOVERY_FINISHED)) {
+			if (action.equals(DISCOVERY_FINISHED)) {
 				LOG.info("Discovery finished");
 				ctx.unregisterReceiver(this);
 				finished.countDown();
-			} else if(action.equals(FOUND)) {
+			} else if (action.equals(FOUND)) {
 				BluetoothDevice d = intent.getParcelableExtra(EXTRA_DEVICE);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Discovered device: " + d.getAddress());
 				addresses.add(d.getAddress());
 			}
@@ -491,13 +491,13 @@ class DroidtoothPlugin implements DuplexPlugin {
 			try {
 				BluetoothSocket s = serverSocket.accept();
 				LOG.info("Incoming connection");
-				if(!socketLatch.set(s)) {
+				if (!socketLatch.set(s)) {
 					LOG.info("Closing redundant connection");
 					s.close();
 				}
-			} catch(IOException e) {
+			} catch (IOException e) {
 				// This is expected when the socket is closed
-				if(LOG.isLoggable(INFO)) LOG.info(e.toString());
+				if (LOG.isLoggable(INFO)) LOG.info(e.toString());
 			}
 		}
 	}
diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java
index e9b645e1c8..dfb5b41f31 100644
--- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java
+++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java
@@ -49,8 +49,8 @@ class DroidtoothTransportConnection implements DuplexTransportConnection {
 
 		public void dispose(boolean exception, boolean recognised)
 				throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) socket.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) socket.close();
 		}
 	}
 
@@ -73,8 +73,8 @@ class DroidtoothTransportConnection implements DuplexTransportConnection {
 		}
 
 		public void dispose(boolean exception) throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) socket.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) socket.close();
 		}
 	}
 }
diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/InsecureBluetooth.java b/briar-android/src/org/briarproject/plugins/droidtooth/InsecureBluetooth.java
index da92a46f3d..572fe2b527 100644
--- a/briar-android/src/org/briarproject/plugins/droidtooth/InsecureBluetooth.java
+++ b/briar-android/src/org/briarproject/plugins/droidtooth/InsecureBluetooth.java
@@ -30,7 +30,7 @@ class InsecureBluetooth {
 	@SuppressLint("NewApi")
 	static BluetoothServerSocket listen(BluetoothAdapter adapter, String name,
 			UUID uuid) throws IOException {
-		if(Build.VERSION.SDK_INT >= 10) {
+		if (Build.VERSION.SDK_INT >= 10) {
 			LOG.info("Listening with new API");
 			return adapter.listenUsingInsecureRfcommWithServiceRecord(name,
 					uuid);
@@ -42,13 +42,13 @@ class InsecureBluetooth {
 					+ ".RfcommChannelPicker";
 			Class<?> channelPickerClass = null;
 			Class<?>[] children = BluetoothAdapter.class.getDeclaredClasses();
-			for(Class<?> c : children) {
-				if(c.getCanonicalName().equals(className)) {
+			for (Class<?> c : children) {
+				if (c.getCanonicalName().equals(className)) {
 					channelPickerClass = c;
 					break;
 				}
 			}
-			if(channelPickerClass == null)
+			if (channelPickerClass == null)
 				throw new IOException("Can't find channel picker class");
 			Constructor<?> constructor =
 					channelPickerClass.getDeclaredConstructor(UUID.class);
@@ -58,7 +58,7 @@ class InsecureBluetooth {
 					channelPickerClass.getDeclaredMethod("nextChannel");
 			nextChannel.setAccessible(true);
 			int channel = (Integer) nextChannel.invoke(channelPicker);
-			if(channel == -1) throw new IOException("No available channels");
+			if (channel == -1) throw new IOException("No available channels");
 			// Listen on the channel
 			BluetoothServerSocket socket = listen(channel);
 			// Add a service record
@@ -72,7 +72,7 @@ class InsecureBluetooth {
 			addRfcommServiceRecord.setAccessible(true);
 			int handle = (Integer) addRfcommServiceRecord.invoke(mService, name,
 					new ParcelUuid(uuid), channel, new Binder());
-			if(handle == -1) {
+			if (handle == -1) {
 				socket.close();
 				throw new IOException("Can't register SDP record for " + name);
 			}
@@ -84,16 +84,16 @@ class InsecureBluetooth {
 			setCloseHandler.setAccessible(true);
 			setCloseHandler.invoke(socket, mHandler, handle);
 			return socket;
-		} catch(NoSuchMethodException e) {
+		} catch (NoSuchMethodException e) {
 			throw new IOException(e.toString());
-		} catch(NoSuchFieldException e) {
+		} catch (NoSuchFieldException e) {
 			throw new IOException(e.toString());
-		} catch(IllegalAccessException e) {
+		} catch (IllegalAccessException e) {
 			throw new IOException(e.toString());
-		} catch(InstantiationException e) {
+		} catch (InstantiationException e) {
 			throw new IOException(e.toString());
-		} catch(InvocationTargetException e) {
-			if(e.getCause() instanceof IOException) {
+		} catch (InvocationTargetException e) {
+			if (e.getCause() instanceof IOException) {
 				throw (IOException) e.getCause();
 			} else {
 				throw new IOException(e.toString());
@@ -116,21 +116,21 @@ class InsecureBluetooth {
 					mSocket.getClass().getDeclaredMethod("bindListen");
 			bindListen.setAccessible(true);
 			int errno = (Integer) bindListen.invoke(mSocket);
-			if(errno != 0) {
+			if (errno != 0) {
 				socket.close();
 				throw new IOException("Can't bind: errno " + errno);
 			}
 			return socket;
-		} catch(NoSuchMethodException e) {
+		} catch (NoSuchMethodException e) {
 			throw new IOException(e.toString());
-		} catch(NoSuchFieldException e) {
+		} catch (NoSuchFieldException e) {
 			throw new IOException(e.toString());
-		} catch(IllegalAccessException e) {
+		} catch (IllegalAccessException e) {
 			throw new IOException(e.toString());
-		} catch(InstantiationException e) {
+		} catch (InstantiationException e) {
 			throw new IOException(e.toString());
-		} catch(InvocationTargetException e) {
-			if(e.getCause() instanceof IOException) {
+		} catch (InvocationTargetException e) {
+			if (e.getCause() instanceof IOException) {
 				throw (IOException) e.getCause();
 			} else {
 				throw new IOException(e.toString());
@@ -141,7 +141,7 @@ class InsecureBluetooth {
 	@SuppressLint("NewApi")
 	static BluetoothSocket createSocket(BluetoothDevice device, UUID uuid)
 			throws IOException {
-		if(Build.VERSION.SDK_INT >= 10) {
+		if (Build.VERSION.SDK_INT >= 10) {
 			LOG.info("Creating socket with new API");
 			return device.createInsecureRfcommSocketToServiceRecord(uuid);
 		}
@@ -154,14 +154,14 @@ class InsecureBluetooth {
 			constructor.setAccessible(true);
 			return constructor.newInstance(TYPE_RFCOMM, -1, false, true, device,
 					-1, new ParcelUuid(uuid));
-		} catch(NoSuchMethodException e) {
+		} catch (NoSuchMethodException e) {
 			throw new IOException(e.toString());
-		} catch(IllegalAccessException e) {
+		} catch (IllegalAccessException e) {
 			throw new IOException(e.toString());
-		} catch(InstantiationException e) {
+		} catch (InstantiationException e) {
 			throw new IOException(e.toString());
-		} catch(InvocationTargetException e) {
-			if(e.getCause() instanceof IOException) {
+		} catch (InvocationTargetException e) {
+			if (e.getCause() instanceof IOException) {
 				throw (IOException) e.getCause();
 			} else {
 				throw new IOException(e.toString());
diff --git a/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java b/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java
index a7689bbda8..70bd116a03 100644
--- a/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java
+++ b/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java
@@ -45,7 +45,7 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
 	@Override
 	public void stop() {
 		running = false;
-		if(networkStateReceiver != null)
+		if (networkStateReceiver != null)
 			appContext.unregisterReceiver(networkStateReceiver);
 		tryToClose(socket);
 	}
@@ -54,13 +54,13 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
 
 		@Override
 		public void onReceive(Context ctx, Intent i) {
-			if(!running) return;
+			if (!running) return;
 			Object o = ctx.getSystemService(CONNECTIVITY_SERVICE);
 			ConnectivityManager cm = (ConnectivityManager) o;
 			NetworkInfo net = cm.getActiveNetworkInfo();
-			if(net != null && net.getType() == TYPE_WIFI && net.isConnected()) {
+			if (net != null && net.getType() == TYPE_WIFI && net.isConnected()) {
 				LOG.info("Connected to Wi-Fi");
-				if(socket == null || socket.isClosed()) bind();
+				if (socket == null || socket.isClosed()) bind();
 			} else {
 				LOG.info("Not connected to Wi-Fi");
 				tryToClose(socket);
diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java
index 264f2ee992..a916ac677d 100644
--- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java
+++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java
@@ -100,7 +100,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 		this.maxLatency = maxLatency;
 		this.maxIdleTime = maxIdleTime;
 		this.pollingInterval = pollingInterval;
-		if(maxIdleTime > Integer.MAX_VALUE / 2)
+		if (maxIdleTime > Integer.MAX_VALUE / 2)
 			socketTimeout = Integer.MAX_VALUE;
 		else socketTimeout = maxIdleTime * 2;
 		torDirectory = appContext.getDir("tor", MODE_PRIVATE);
@@ -131,16 +131,16 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 		try {
 			controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
 			LOG.info("Tor is already running");
-		} catch(IOException e) {
+		} catch (IOException e) {
 			LOG.info("Tor is not running");
 			startProcess = true;
 			// Install the binary, possibly overwriting an older version
-			if(!installBinary()) {
+			if (!installBinary()) {
 				LOG.warning("Could not install Tor binary");
 				return false;
 			}
 			// Install the GeoIP database and config file if necessary
-			if(!isConfigInstalled() && !installConfig()) {
+			if (!isConfigInstalled() && !installConfig()) {
 				LOG.info("Could not install Tor config");
 				return false;
 			}
@@ -160,31 +160,31 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 			Process torProcess;
 			try {
 				torProcess = Runtime.getRuntime().exec(cmd, env, torDirectory);
-			} catch(SecurityException e1) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e1.toString(), e1);
+			} catch (SecurityException e1) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e1.toString(), e1);
 				return false;
 			}
 			// Log the process's standard output until it detaches
-			if(LOG.isLoggable(INFO)) {
+			if (LOG.isLoggable(INFO)) {
 				Scanner stdout = new Scanner(torProcess.getInputStream());
-				while(stdout.hasNextLine()) LOG.info(stdout.nextLine());
+				while (stdout.hasNextLine()) LOG.info(stdout.nextLine());
 				stdout.close();
 			}
 			try {
 				// Wait for the process to detach or exit
 				int exit = torProcess.waitFor();
-				if(exit != 0) {
-					if(LOG.isLoggable(WARNING))
+				if (exit != 0) {
+					if (LOG.isLoggable(WARNING))
 						LOG.warning("Tor exited with value " + exit);
 					return false;
 				}
 				// Wait for the auth cookie file to be created/updated
-				if(!latch.await(COOKIE_TIMEOUT, MILLISECONDS)) {
+				if (!latch.await(COOKIE_TIMEOUT, MILLISECONDS)) {
 					LOG.warning("Auth cookie not created");
-					if(LOG.isLoggable(INFO)) listFiles(torDirectory);
+					if (LOG.isLoggable(INFO)) listFiles(torDirectory);
 					return false;
 				}
-			} catch(InterruptedException e1) {
+			} catch (InterruptedException e1) {
 				LOG.warning("Interrupted while starting Tor");
 				Thread.currentThread().interrupt();
 				return false;
@@ -203,9 +203,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 		controlConnection.setEventHandler(this);
 		controlConnection.setEvents(Arrays.asList(EVENTS));
 		// If Tor was already running, find out whether it's bootstrapped
-		if(!startProcess) {
+		if (!startProcess) {
 			String phase = controlConnection.getInfo("status/bootstrap-phase");
-			if(phase != null && phase.contains("PROGRESS=100")) {
+			if (phase != null && phase.contains("PROGRESS=100")) {
 				LOG.info("Tor has already bootstrapped");
 				bootstrapped = true;
 			}
@@ -228,13 +228,13 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 			out = new FileOutputStream(torFile);
 			copy(in, out);
 			// Make the Tor binary executable
-			if(!setExecutable(torFile)) {
+			if (!setExecutable(torFile)) {
 				LOG.warning("Could not make Tor binary executable");
 				return false;
 			}
 			return true;
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			tryToClose(in);
 			tryToClose(out);
 			return false;
@@ -260,8 +260,8 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 			// Create a file to indicate that installation succeeded
 			doneFile.createNewFile();
 			return true;
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			tryToClose(in);
 			tryToClose(out);
 			return false;
@@ -269,12 +269,12 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 	}
 
 	private InputStream getTorInputStream() throws IOException {
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Installing Tor binary for " + architecture);
 		String filename = "tor-" + architecture + ".zip";
 		InputStream in = appContext.getResources().getAssets().open(filename);
 		ZipInputStream zin = new ZipInputStream(in);
-		if(zin.getNextEntry() == null) throw new IOException();
+		if (zin.getNextEntry() == null) throw new IOException();
 		return zin;
 	}
 
@@ -282,7 +282,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 		String filename = "geoip.zip";
 		InputStream in = appContext.getResources().getAssets().open(filename);
 		ZipInputStream zin = new ZipInputStream(in);
-		if(zin.getNextEntry() == null) throw new IOException();
+		if (zin.getNextEntry() == null) throw new IOException();
 		return zin;
 	}
 
@@ -292,9 +292,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 
 	private void copy(InputStream in, OutputStream out) throws IOException {
 		byte[] buf = new byte[4096];
-		while(true) {
+		while (true) {
 			int read = in.read(buf);
-			if(read == -1) break;
+			if (read == -1) break;
 			out.write(buf, 0, read);
 		}
 		in.close();
@@ -303,19 +303,19 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 
 	@SuppressLint("NewApi")
 	private boolean setExecutable(File f) {
-		if(Build.VERSION.SDK_INT >= 9) {
+		if (Build.VERSION.SDK_INT >= 9) {
 			return f.setExecutable(true, true);
 		} else {
 			String[] command = { "chmod", "700", f.getAbsolutePath() };
 			try {
 				return Runtime.getRuntime().exec(command).waitFor() == 0;
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-			} catch(InterruptedException e) {
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (InterruptedException e) {
 				LOG.warning("Interrupted while executing chmod");
 				Thread.currentThread().interrupt();
-			} catch(SecurityException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (SecurityException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 			return false;
 		}
@@ -323,22 +323,22 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 
 	private void tryToClose(InputStream in) {
 		try {
-			if(in != null) in.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (in != null) in.close();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	private void tryToClose(OutputStream out) {
 		try {
-			if(out != null) out.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (out != null) out.close();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	private void listFiles(File f) {
-		if(f.isDirectory()) for(File child : f.listFiles()) listFiles(child);
+		if (f.isDirectory()) for (File child : f.listFiles()) listFiles(child);
 		else LOG.info(f.getAbsolutePath());
 	}
 
@@ -347,9 +347,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 		FileInputStream in = new FileInputStream(f);
 		try {
 			int offset = 0;
-			while(offset < b.length) {
+			while (offset < b.length) {
 				int read = in.read(b, offset, b.length - offset);
-				if(read == -1) throw new EOFException();
+				if (read == -1) throw new EOFException();
 				offset += read;
 			}
 			return b;
@@ -364,19 +364,19 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 				// If there's already a port number stored in config, reuse it
 				String portString = callback.getConfig().get("port");
 				int port;
-				if(StringUtils.isNullOrEmpty(portString)) port = 0;
+				if (StringUtils.isNullOrEmpty(portString)) port = 0;
 				else port = Integer.parseInt(portString);
 				// Bind a server socket to receive connections from Tor
 				ServerSocket ss = null;
 				try {
 					ss = new ServerSocket();
 					ss.bind(new InetSocketAddress("127.0.0.1", port));
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					tryToClose(ss);
 				}
-				if(!running) {
+				if (!running) {
 					tryToClose(ss);
 					return;
 				}
@@ -400,15 +400,15 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 
 	private void tryToClose(ServerSocket ss) {
 		try {
-			if(ss != null) ss.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (ss != null) ss.close();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	private void publishHiddenService(String port) {
-		if(!running) return;
-		if(!hostnameFile.exists()) {
+		if (!running) return;
+		if (!hostnameFile.exists()) {
 			LOG.info("Creating hidden service");
 			try {
 				// Watch for the hostname file being created/updated
@@ -424,15 +424,15 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 				controlConnection.setConf(config);
 				controlConnection.saveConf();
 				// Wait for the hostname file to be created/updated
-				if(!latch.await(HOSTNAME_TIMEOUT, MILLISECONDS)) {
+				if (!latch.await(HOSTNAME_TIMEOUT, MILLISECONDS)) {
 					LOG.warning("Hidden service not created");
-					if(LOG.isLoggable(INFO)) listFiles(torDirectory);
+					if (LOG.isLoggable(INFO)) listFiles(torDirectory);
 					return;
 				}
-				if(!running) return;
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-			} catch(InterruptedException e) {
+				if (!running) return;
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (InterruptedException e) {
 				LOG.warning("Interrupted while creating hidden service");
 				Thread.currentThread().interrupt();
 				return;
@@ -441,24 +441,24 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 		// Publish the hidden service's onion hostname in transport properties
 		try {
 			String hostname = new String(read(hostnameFile), "UTF-8").trim();
-			if(LOG.isLoggable(INFO)) LOG.info("Hidden service " + hostname);
+			if (LOG.isLoggable(INFO)) LOG.info("Hidden service " + hostname);
 			TransportProperties p = new TransportProperties();
 			p.put("onion", hostname);
 			callback.mergeLocalProperties(p);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	private void acceptContactConnections(ServerSocket ss) {
-		while(running) {
+		while (running) {
 			Socket s;
 			try {
 				s = ss.accept();
 				s.setSoTimeout(socketTimeout);
-			} catch(IOException e) {
+			} catch (IOException e) {
 				// This is expected when the socket is closed
-				if(LOG.isLoggable(INFO)) LOG.info(e.toString());
+				if (LOG.isLoggable(INFO)) LOG.info(e.toString());
 				return;
 			}
 			LOG.info("Connection received");
@@ -468,9 +468,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 	}
 
 	private void enableNetwork(boolean enable) throws IOException {
-		if(!running) return;
-		if(LOG.isLoggable(INFO)) LOG.info("Enabling network: " + enable);
-		if(!enable) circuitBuilt.set(false);
+		if (!running) return;
+		if (LOG.isLoggable(INFO)) LOG.info("Enabling network: " + enable);
+		if (!enable) circuitBuilt.set(false);
 		networkEnabled = enable;
 		controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
 	}
@@ -478,21 +478,21 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 	public void stop() throws IOException {
 		running = false;
 		tryToClose(socket);
-		if(networkStateReceiver != null)
+		if (networkStateReceiver != null)
 			appContext.unregisterReceiver(networkStateReceiver);
 		try {
 			LOG.info("Stopping Tor");
-			if(controlSocket == null)
+			if (controlSocket == null)
 				controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
-			if(controlConnection == null) {
+			if (controlConnection == null) {
 				controlConnection = new TorControlConnection(controlSocket);
 				controlConnection.authenticate(read(cookieFile));
 			}
 			controlConnection.setConf("DisableNetwork", "1");
 			controlConnection.shutdownTor("TERM");
 			controlSocket.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
@@ -509,41 +509,41 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 	}
 
 	public void poll(Collection<ContactId> connected) {
-		if(!isRunning()) return;
-		for(ContactId c : callback.getRemoteProperties().keySet())
-			if(!connected.contains(c)) connectAndCallBack(c);
+		if (!isRunning()) return;
+		for (ContactId c : callback.getRemoteProperties().keySet())
+			if (!connected.contains(c)) connectAndCallBack(c);
 	}
 
 	private void connectAndCallBack(final ContactId c) {
 		ioExecutor.execute(new Runnable() {
 			public void run() {
 				DuplexTransportConnection d = createConnection(c);
-				if(d != null) callback.outgoingConnectionCreated(c, d);
+				if (d != null) callback.outgoingConnectionCreated(c, d);
 			}
 		});
 	}
 
 	public DuplexTransportConnection createConnection(ContactId c) {
-		if(!isRunning()) return null;
+		if (!isRunning()) return null;
 		TransportProperties p = callback.getRemoteProperties().get(c);
-		if(p == null) return null;
+		if (p == null) return null;
 		String onion = p.get("onion");
-		if(StringUtils.isNullOrEmpty(onion)) return null;
-		if(!ONION.matcher(onion).matches()) {
-			if(LOG.isLoggable(INFO)) LOG.info("Invalid hostname: " + onion);
+		if (StringUtils.isNullOrEmpty(onion)) return null;
+		if (!ONION.matcher(onion).matches()) {
+			if (LOG.isLoggable(INFO)) LOG.info("Invalid hostname: " + onion);
 			return null;
 		}
 		try {
-			if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + onion);
+			if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + onion);
 			controlConnection.forgetHiddenService(onion.substring(0, 16));
 			Socks5Proxy proxy = new Socks5Proxy("127.0.0.1", SOCKS_PORT);
 			proxy.resolveAddrLocally(false);
 			Socket s = new SocksSocket(proxy, onion, 80);
 			s.setSoTimeout(socketTimeout);
-			if(LOG.isLoggable(INFO)) LOG.info("Connected to " + onion);
+			if (LOG.isLoggable(INFO)) LOG.info("Connected to " + onion);
 			return new TorTransportConnection(this, s);
-		} catch(IOException e) {
-			if(LOG.isLoggable(INFO)) LOG.info("Could not connect to " + onion);
+		} catch (IOException e) {
+			if (LOG.isLoggable(INFO)) LOG.info("Could not connect to " + onion);
 			return null;
 		}
 	}
@@ -558,16 +558,16 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 	}
 
 	public void circuitStatus(String status, String id, String path) {
-		if(status.equals("BUILT") && !circuitBuilt.getAndSet(true)) {
+		if (status.equals("BUILT") && !circuitBuilt.getAndSet(true)) {
 			LOG.info("First circuit built");
-			if(isRunning()) callback.pollNow();
+			if (isRunning()) callback.pollNow();
 		}
 	}
 
 	public void streamStatus(String status, String id, String target) {}
 
 	public void orConnStatus(String status, String orName) {
-		if(LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
+		if (LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
 	}
 
 	public void bandwidthUsed(long read, long written) {}
@@ -575,10 +575,10 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 	public void newDescriptors(List<String> orList) {}
 
 	public void message(String severity, String msg) {
-		if(LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
-		if(severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
+		if (LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
+		if (severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
 			bootstrapped = true;
-			if(isRunning()) callback.pollNow();
+			if (isRunning()) callback.pollNow();
 		}
 	}
 
@@ -604,26 +604,26 @@ class TorPlugin implements DuplexPlugin, EventHandler {
 
 		@Override
 		public void onReceive(Context ctx, Intent i) {
-			if(!running) return;
+			if (!running) return;
 			boolean online = !i.getBooleanExtra(EXTRA_NO_CONNECTIVITY, false);
-			if(online) {
+			if (online) {
 				// Some devices fail to set EXTRA_NO_CONNECTIVITY, double check
 				Object o = ctx.getSystemService(CONNECTIVITY_SERVICE);
 				ConnectivityManager cm = (ConnectivityManager) o;
 				NetworkInfo net = cm.getActiveNetworkInfo();
-				if(net == null || !net.isConnected()) online = false;
+				if (net == null || !net.isConnected()) online = false;
 			}
 			String country = locationUtils.getCurrentCountry();
-			if(LOG.isLoggable(INFO)) {
+			if (LOG.isLoggable(INFO)) {
 				LOG.info("Online: " + online);
-				if("".equals(country)) LOG.info("Country code unknown");
+				if ("".equals(country)) LOG.info("Country code unknown");
 				else LOG.info("Country code: " + country);
 			}
 			boolean blocked = TorNetworkMetadata.isTorProbablyBlocked(country);
 			try {
 				enableNetwork(online && !blocked);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java b/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java
index 32f351012a..9e38a5a376 100644
--- a/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java
+++ b/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java
@@ -40,21 +40,21 @@ public class TorPluginFactory implements DuplexPluginFactory {
 	public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
 		// Check that we have a Tor binary for this architecture
 		String architecture = null;
-		for(String abi : AndroidUtils.getSupportedArchitectures()) {
-			if(abi.startsWith("x86")) {
+		for (String abi : AndroidUtils.getSupportedArchitectures()) {
+			if (abi.startsWith("x86")) {
 				architecture = "x86";
 				break;
-			} else if(abi.startsWith("armeabi")) {
+			} else if (abi.startsWith("armeabi")) {
 				architecture = "arm";
 				break;
 			}
 		}
-		if(architecture == null) {
+		if (architecture == null) {
 			LOG.info("Tor is not supported on this architecture");
 			return null;
 		}
 		// Use position-independent executable for SDK >= 16
-		if(Build.VERSION.SDK_INT >= 16) architecture += "-pie";
+		if (Build.VERSION.SDK_INT >= 16) architecture += "-pie";
 		return new TorPlugin(ioExecutor,appContext, locationUtils, callback,
 				architecture, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
 	}
diff --git a/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java b/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java
index 4640eb1f6b..a847bc9123 100644
--- a/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java
+++ b/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java
@@ -48,8 +48,8 @@ class TorTransportConnection implements DuplexTransportConnection {
 
 		public void dispose(boolean exception, boolean recognised)
 				throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) socket.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) socket.close();
 		}
 	}
 
@@ -72,8 +72,8 @@ class TorTransportConnection implements DuplexTransportConnection {
 		}
 
 		public void dispose(boolean exception) throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) socket.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) socket.close();
 		}
 	}
 }
diff --git a/briar-android/src/org/briarproject/system/AndroidFileUtils.java b/briar-android/src/org/briarproject/system/AndroidFileUtils.java
index 62d60102d0..ae8f3e7bb3 100644
--- a/briar-android/src/org/briarproject/system/AndroidFileUtils.java
+++ b/briar-android/src/org/briarproject/system/AndroidFileUtils.java
@@ -14,7 +14,7 @@ public class AndroidFileUtils implements FileUtils {
 	@SuppressLint("NewApi")
 	@SuppressWarnings("deprecation")
 	public long getTotalSpace(File f) throws IOException {
-		if(Build.VERSION.SDK_INT >= 9) return f.getTotalSpace();
+		if (Build.VERSION.SDK_INT >= 9) return f.getTotalSpace();
 		StatFs s = new StatFs(f.getAbsolutePath());
 		// These deprecated methods are the best thing available for SDK < 9
 		return (long) s.getBlockCount() * s.getBlockSize();
@@ -23,7 +23,7 @@ public class AndroidFileUtils implements FileUtils {
 	@SuppressLint("NewApi")
 	@SuppressWarnings("deprecation")
 	public long getFreeSpace(File f) throws IOException {
-		if(Build.VERSION.SDK_INT >= 9) return f.getUsableSpace();
+		if (Build.VERSION.SDK_INT >= 9) return f.getUsableSpace();
 		StatFs s = new StatFs(f.getAbsolutePath());
 		// These deprecated methods are the best thing available for SDK < 9
 		return (long) s.getAvailableBlocks() * s.getBlockSize();
diff --git a/briar-android/src/org/briarproject/system/AndroidLocationUtils.java b/briar-android/src/org/briarproject/system/AndroidLocationUtils.java
index a73c9233bf..f8fe98f23c 100644
--- a/briar-android/src/org/briarproject/system/AndroidLocationUtils.java
+++ b/briar-android/src/org/briarproject/system/AndroidLocationUtils.java
@@ -47,14 +47,14 @@ class AndroidLocationUtils implements LocationUtils {
 	@SuppressLint("DefaultLocale")
 	public String getCurrentCountry() {
 		String countryCode = getCountryFromPhoneNetwork();
-		if(!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
+		if (!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
 		// Disabled because it involves a network call; requires
 		// ACCESS_FINE_LOCATION
 		// countryCode = getCountryFromLocation();
-		// if(!TextUtils.isEmpty(countryCode)) return countryCode;
+		// if (!TextUtils.isEmpty(countryCode)) return countryCode;
 		LOG.info("Falling back to SIM card country");
 		countryCode = getCountryFromSimCard();
-		if(!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
+		if (!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
 		LOG.info("Falling back to user-defined locale");
 		return Locale.getDefault().getCountry();
 	}
diff --git a/briar-android/src/org/briarproject/system/AndroidSeedProvider.java b/briar-android/src/org/briarproject/system/AndroidSeedProvider.java
index 2cc9ac48d5..530e4b3ca3 100644
--- a/briar-android/src/org/briarproject/system/AndroidSeedProvider.java
+++ b/briar-android/src/org/briarproject/system/AndroidSeedProvider.java
@@ -15,10 +15,10 @@ class AndroidSeedProvider extends LinuxSeedProvider {
 		out.writeInt(android.os.Process.myTid());
 		out.writeInt(android.os.Process.myUid());
 		String fingerprint = Build.FINGERPRINT;
-		if(fingerprint != null) out.writeUTF(fingerprint);
-		if(Build.VERSION.SDK_INT >= 9) {
+		if (fingerprint != null) out.writeUTF(fingerprint);
+		if (Build.VERSION.SDK_INT >= 9) {
 			String serial = Build.SERIAL;
-			if(serial != null) out.writeUTF(serial);
+			if (serial != null) out.writeUTF(serial);
 		}
 		super.writeToEntropyPool(out);
 	}
diff --git a/briar-api/src/org/briarproject/api/Author.java b/briar-api/src/org/briarproject/api/Author.java
index 2f1cae443a..c4f3c050bf 100644
--- a/briar-api/src/org/briarproject/api/Author.java
+++ b/briar-api/src/org/briarproject/api/Author.java
@@ -17,10 +17,10 @@ public class Author {
 		int length;
 		try {
 			length = name.getBytes("UTF-8").length;
-		} catch(UnsupportedEncodingException e) {
+		} catch (UnsupportedEncodingException e) {
 			throw new RuntimeException(e);
 		}
-		if(length == 0 || length > MAX_AUTHOR_NAME_LENGTH)
+		if (length == 0 || length > MAX_AUTHOR_NAME_LENGTH)
 			throw new IllegalArgumentException();
 		this.id = id;
 		this.name = name;
diff --git a/briar-api/src/org/briarproject/api/AuthorId.java b/briar-api/src/org/briarproject/api/AuthorId.java
index fd1102b51b..0ee86a33a6 100644
--- a/briar-api/src/org/briarproject/api/AuthorId.java
+++ b/briar-api/src/org/briarproject/api/AuthorId.java
@@ -14,7 +14,7 @@ public class AuthorId extends UniqueId {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof AuthorId)
+		if (o instanceof AuthorId)
 			return Arrays.equals(id, ((AuthorId) o).id);
 		return false;
 	}
diff --git a/briar-api/src/org/briarproject/api/Bytes.java b/briar-api/src/org/briarproject/api/Bytes.java
index 0c92b4104c..91660eb7b3 100644
--- a/briar-api/src/org/briarproject/api/Bytes.java
+++ b/briar-api/src/org/briarproject/api/Bytes.java
@@ -21,13 +21,13 @@ public class Bytes {
 	public int hashCode() {
 		// Thread-safe because if two or more threads check and update the
 		// value, they'll calculate the same value
-		if(hashCode == -1) hashCode = Arrays.hashCode(bytes);
+		if (hashCode == -1) hashCode = Arrays.hashCode(bytes);
 		return hashCode;
 	}
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof Bytes)
+		if (o instanceof Bytes)
 			return Arrays.equals(bytes, ((Bytes) o).bytes);
 		return false;
 	}
diff --git a/briar-api/src/org/briarproject/api/Contact.java b/briar-api/src/org/briarproject/api/Contact.java
index 8e850e411a..fa03b83681 100644
--- a/briar-api/src/org/briarproject/api/Contact.java
+++ b/briar-api/src/org/briarproject/api/Contact.java
@@ -31,7 +31,7 @@ public class Contact {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof Contact) return id.equals(((Contact) o).id);
+		if (o instanceof Contact) return id.equals(((Contact) o).id);
 		return false;
 	}
 }
diff --git a/briar-api/src/org/briarproject/api/ContactId.java b/briar-api/src/org/briarproject/api/ContactId.java
index d5d33e6236..7a60116027 100644
--- a/briar-api/src/org/briarproject/api/ContactId.java
+++ b/briar-api/src/org/briarproject/api/ContactId.java
@@ -23,7 +23,7 @@ public class ContactId {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof ContactId) return id == ((ContactId) o).id;
+		if (o instanceof ContactId) return id == ((ContactId) o).id;
 		return false;
 	}
 }
diff --git a/briar-api/src/org/briarproject/api/StringMap.java b/briar-api/src/org/briarproject/api/StringMap.java
index 63685438ec..e0480bbfa8 100644
--- a/briar-api/src/org/briarproject/api/StringMap.java
+++ b/briar-api/src/org/briarproject/api/StringMap.java
@@ -17,9 +17,9 @@ abstract class StringMap extends Hashtable<String, String> {
 
 	public boolean getBoolean(String key, boolean defaultValue) {
 		String s = get(key);
-		if(s == null) return defaultValue;
-		if("true".equals(s)) return true;
-		if("false".equals(s)) return false;
+		if (s == null) return defaultValue;
+		if ("true".equals(s)) return true;
+		if ("false".equals(s)) return false;
 		return defaultValue;
 	}
 
diff --git a/briar-api/src/org/briarproject/api/TransportId.java b/briar-api/src/org/briarproject/api/TransportId.java
index e4a57a6d7c..9f123ab831 100644
--- a/briar-api/src/org/briarproject/api/TransportId.java
+++ b/briar-api/src/org/briarproject/api/TransportId.java
@@ -10,7 +10,7 @@ public class TransportId {
 	private final String id;
 
 	public TransportId(String id) {
-		if(id.length() == 0 || id.length() > MAX_TRANSPORT_ID_LENGTH)
+		if (id.length() == 0 || id.length() > MAX_TRANSPORT_ID_LENGTH)
 			throw new IllegalArgumentException();
 		this.id = id;
 	}
@@ -21,7 +21,7 @@ public class TransportId {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof TransportId) return id.equals(((TransportId) o).id);
+		if (o instanceof TransportId) return id.equals(((TransportId) o).id);
 		return false;
 	}
 
diff --git a/briar-api/src/org/briarproject/api/UniqueId.java b/briar-api/src/org/briarproject/api/UniqueId.java
index 75cf1f6509..0c690ff2fd 100644
--- a/briar-api/src/org/briarproject/api/UniqueId.java
+++ b/briar-api/src/org/briarproject/api/UniqueId.java
@@ -12,7 +12,7 @@ public abstract class UniqueId {
 	private int hashCode = -1;
 
 	protected UniqueId(byte[] id) {
-		if(id.length != LENGTH) throw new IllegalArgumentException();
+		if (id.length != LENGTH) throw new IllegalArgumentException();
 		this.id = id;
 	}
 
@@ -24,7 +24,7 @@ public abstract class UniqueId {
 	public int hashCode() {
 		// Thread-safe because if two or more threads check and update the
 		// value, they'll calculate the same value
-		if(hashCode == -1) hashCode = Arrays.hashCode(id);
+		if (hashCode == -1) hashCode = Arrays.hashCode(id);
 		return hashCode;
 	}
 }
diff --git a/briar-api/src/org/briarproject/api/crypto/SecretKey.java b/briar-api/src/org/briarproject/api/crypto/SecretKey.java
index f863bbebee..9c34e91a05 100644
--- a/briar-api/src/org/briarproject/api/crypto/SecretKey.java
+++ b/briar-api/src/org/briarproject/api/crypto/SecretKey.java
@@ -8,7 +8,7 @@ public class SecretKey {
 	private final byte[] key;
 
 	public SecretKey(byte[] key) {
-		if(key.length != LENGTH) throw new IllegalArgumentException();
+		if (key.length != LENGTH) throw new IllegalArgumentException();
 		this.key = key;
 	}
 
diff --git a/briar-api/src/org/briarproject/api/messaging/Group.java b/briar-api/src/org/briarproject/api/messaging/Group.java
index 2a6a083b14..90e6953874 100644
--- a/briar-api/src/org/briarproject/api/messaging/Group.java
+++ b/briar-api/src/org/briarproject/api/messaging/Group.java
@@ -16,12 +16,12 @@ public class Group {
 		int length;
 		try {
 			length = name.getBytes("UTF-8").length;
-		} catch(UnsupportedEncodingException e) {
+		} catch (UnsupportedEncodingException e) {
 			throw new RuntimeException(e);
 		}
-		if(length == 0 || length > MAX_GROUP_NAME_LENGTH)
+		if (length == 0 || length > MAX_GROUP_NAME_LENGTH)
 			throw new IllegalArgumentException();
-		if(salt.length != GROUP_SALT_LENGTH)
+		if (salt.length != GROUP_SALT_LENGTH)
 			throw new IllegalArgumentException();
 		this.id = id;
 		this.name = name;
diff --git a/briar-api/src/org/briarproject/api/messaging/GroupId.java b/briar-api/src/org/briarproject/api/messaging/GroupId.java
index d34ccebcbd..7732774e43 100644
--- a/briar-api/src/org/briarproject/api/messaging/GroupId.java
+++ b/briar-api/src/org/briarproject/api/messaging/GroupId.java
@@ -15,7 +15,7 @@ public class GroupId extends UniqueId {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof GroupId)
+		if (o instanceof GroupId)
 			return Arrays.equals(id, ((GroupId) o).id);
 		return false;
 	}
diff --git a/briar-api/src/org/briarproject/api/messaging/MessageId.java b/briar-api/src/org/briarproject/api/messaging/MessageId.java
index 1ba329aa2b..a2a79c43de 100644
--- a/briar-api/src/org/briarproject/api/messaging/MessageId.java
+++ b/briar-api/src/org/briarproject/api/messaging/MessageId.java
@@ -16,7 +16,7 @@ public class MessageId extends UniqueId {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof MessageId)
+		if (o instanceof MessageId)
 			return Arrays.equals(id, ((MessageId) o).id);
 		return false;
 	}
diff --git a/briar-api/src/org/briarproject/api/transport/TemporarySecret.java b/briar-api/src/org/briarproject/api/transport/TemporarySecret.java
index 37ed630e46..c2a1108208 100644
--- a/briar-api/src/org/briarproject/api/transport/TemporarySecret.java
+++ b/briar-api/src/org/briarproject/api/transport/TemporarySecret.java
@@ -63,7 +63,7 @@ public class TemporarySecret extends Endpoint {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof TemporarySecret) {
+		if (o instanceof TemporarySecret) {
 			TemporarySecret s = (TemporarySecret) o;
 			return contactId.equals(s.contactId) &&
 					transportId.equals(s.transportId) && period == s.period;
diff --git a/briar-core/src/org/briarproject/crypto/AuthenticatedCipherImpl.java b/briar-core/src/org/briarproject/crypto/AuthenticatedCipherImpl.java
index 671a73e855..c212132873 100644
--- a/briar-core/src/org/briarproject/crypto/AuthenticatedCipherImpl.java
+++ b/briar-core/src/org/briarproject/crypto/AuthenticatedCipherImpl.java
@@ -26,15 +26,15 @@ class AuthenticatedCipherImpl implements AuthenticatedCipher {
 	public int process(byte[] input, int inputOff, int len, byte[] output,
 			int outputOff) throws GeneralSecurityException {
 		int processed = 0;
-		if(len != 0) {
+		if (len != 0) {
 			processed = cipher.processBytes(input, inputOff, len, output,
 					outputOff);
 		}
 		try {
 			return processed + cipher.doFinal(output, outputOff + processed);
-		} catch(DataLengthException e) {
+		} catch (DataLengthException e) {
 			throw new GeneralSecurityException(e.getMessage());
-		} catch(InvalidCipherTextException e) {
+		} catch (InvalidCipherTextException e) {
 			throw new GeneralSecurityException(e.getMessage());
 		}
 	}
@@ -46,7 +46,7 @@ class AuthenticatedCipherImpl implements AuthenticatedCipher {
 		AEADParameters params = new AEADParameters(k, MAC_LENGTH * 8, iv, iv);
 		try {
 			cipher.init(encrypt, params);
-		} catch(IllegalArgumentException e) {
+		} catch (IllegalArgumentException e) {
 			throw new GeneralSecurityException(e.getMessage());
 		}
 	}
diff --git a/briar-core/src/org/briarproject/crypto/CombinedSecureRandom.java b/briar-core/src/org/briarproject/crypto/CombinedSecureRandom.java
index 7f36bb7c4e..9e8631fd3b 100644
--- a/briar-core/src/org/briarproject/crypto/CombinedSecureRandom.java
+++ b/briar-core/src/org/briarproject/crypto/CombinedSecureRandom.java
@@ -24,17 +24,17 @@ class CombinedSecureRandom extends SecureRandom {
 		private final SecureRandom[] randoms;
 
 		private CombinedSecureRandomSpi(SecureRandom... randoms) {
-			if(randoms.length < 2) throw new IllegalArgumentException();
+			if (randoms.length < 2) throw new IllegalArgumentException();
 			this.randoms = randoms;
 		}
 
 		@Override
 		protected byte[] engineGenerateSeed(int numBytes) {
 			byte[] combined = new byte[numBytes];
-			for(SecureRandom random : randoms) {
+			for (SecureRandom random : randoms) {
 				byte[] b = random.generateSeed(numBytes);
 				int length = Math.min(numBytes, b.length);
-				for(int i = 0; i < length; i++)
+				for (int i = 0; i < length; i++)
 					combined[i] = (byte) (combined[i] ^ b[i]);
 			}
 			return combined;
@@ -43,16 +43,16 @@ class CombinedSecureRandom extends SecureRandom {
 		@Override
 		protected void engineNextBytes(byte[] b) {
 			byte[] temp = new byte[b.length];
-			for(SecureRandom random : randoms) {
+			for (SecureRandom random : randoms) {
 				random.nextBytes(temp);
-				for(int i = 0; i < b.length; i++)
+				for (int i = 0; i < b.length; i++)
 					b[i] = (byte) (b[i] ^ temp[i]);
 			}
 		}
 
 		@Override
 		protected void engineSetSeed(byte[] seed) {
-			for(SecureRandom random : randoms) random.setSeed(seed);
+			for (SecureRandom random : randoms) random.setSeed(seed);
 		}
 	}
 
diff --git a/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java b/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java
index 989a9b28a6..7fbcc7c2cc 100644
--- a/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java
+++ b/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java
@@ -79,9 +79,9 @@ class CryptoComponentImpl implements CryptoComponent {
 
 	@Inject
 	CryptoComponentImpl(SeedProvider r) {
-		if(!FortunaSecureRandom.selfTest()) throw new RuntimeException();
+		if (!FortunaSecureRandom.selfTest()) throw new RuntimeException();
 		SecureRandom secureRandom1 = new SecureRandom();
-		if(LOG.isLoggable(INFO)) {
+		if (LOG.isLoggable(INFO)) {
 			String provider = secureRandom1.getProvider().getName();
 			String algorithm = secureRandom1.getAlgorithm();
 			LOG.info("Default SecureRandom: " + provider + " " + algorithm);
@@ -168,7 +168,7 @@ class CryptoComponentImpl implements CryptoComponent {
 	}
 
 	public int[] deriveConfirmationCodes(byte[] secret) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
 		byte[] alice = counterModeKdf(secret, CODE, 0);
 		byte[] bob = counterModeKdf(secret, CODE, 1);
@@ -179,7 +179,7 @@ class CryptoComponentImpl implements CryptoComponent {
 	}
 
 	public byte[][] deriveInvitationNonces(byte[] secret) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
 		byte[] alice = counterModeKdf(secret, NONCE, 0);
 		byte[] bob = counterModeKdf(secret, NONCE, 1);
@@ -193,7 +193,7 @@ class CryptoComponentImpl implements CryptoComponent {
 		byte[] ourHash = messageDigest.digest(ourPublicKey);
 		byte[] theirHash = messageDigest.digest(theirPublicKey);
 		byte[] aliceInfo, bobInfo;
-		if(alice) {
+		if (alice) {
 			aliceInfo = ourHash;
 			bobInfo = theirHash;
 		} else {
@@ -212,9 +212,9 @@ class CryptoComponentImpl implements CryptoComponent {
 	// Package access for testing
 	byte[] deriveSharedSecret(PrivateKey priv, PublicKey pub)
 			throws GeneralSecurityException {
-		if(!(priv instanceof Sec1PrivateKey))
+		if (!(priv instanceof Sec1PrivateKey))
 			throw new IllegalArgumentException();
-		if(!(pub instanceof Sec1PublicKey))
+		if (!(pub instanceof Sec1PublicKey))
 			throw new IllegalArgumentException();
 		ECPrivateKeyParameters ecPriv = ((Sec1PrivateKey) priv).getKey();
 		ECPublicKeyParameters ecPub = ((Sec1PublicKey) pub).getKey();
@@ -223,46 +223,46 @@ class CryptoComponentImpl implements CryptoComponent {
 		agreement.init(ecPriv);
 		byte[] secret = agreement.calculateAgreement(ecPub).toByteArray();
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Deriving shared secret took " + duration + " ms");
 		return secret;
 	}
 
 	public byte[] deriveGroupSalt(byte[] secret) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
 		return counterModeKdf(secret, SALT, 0);
 	}
 
 	public byte[] deriveInitialSecret(byte[] secret, int transportIndex) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
-		if(transportIndex < 0) throw new IllegalArgumentException();
+		if (transportIndex < 0) throw new IllegalArgumentException();
 		return counterModeKdf(secret, FIRST, transportIndex);
 	}
 
 	public byte[] deriveNextSecret(byte[] secret, long period) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
-		if(period < 0 || period > MAX_32_BIT_UNSIGNED)
+		if (period < 0 || period > MAX_32_BIT_UNSIGNED)
 			throw new IllegalArgumentException();
 		return counterModeKdf(secret, ROTATE, period);
 	}
 
 	public SecretKey deriveTagKey(byte[] secret, boolean alice) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
-		if(alice) return deriveKey(secret, A_TAG, 0);
+		if (alice) return deriveKey(secret, A_TAG, 0);
 		else return deriveKey(secret, B_TAG, 0);
 	}
 
 	public SecretKey deriveFrameKey(byte[] secret, long streamNumber,
 			boolean alice) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
-		if(streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED)
+		if (streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED)
 			throw new IllegalArgumentException();
-		if(alice) return deriveKey(secret, A_FRAME, streamNumber);
+		if (alice) return deriveKey(secret, A_FRAME, streamNumber);
 		else return deriveKey(secret, B_FRAME, streamNumber);
 	}
 
@@ -271,10 +271,10 @@ class CryptoComponentImpl implements CryptoComponent {
 	}
 
 	public void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber) {
-		if(tag.length < TAG_LENGTH) throw new IllegalArgumentException();
-		if(streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED)
+		if (tag.length < TAG_LENGTH) throw new IllegalArgumentException();
+		if (streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED)
 			throw new IllegalArgumentException();
-		for(int i = 0; i < TAG_LENGTH; i++) tag[i] = 0;
+		for (int i = 0; i < TAG_LENGTH; i++) tag[i] = 0;
 		ByteUtils.writeUint32(streamNumber, tag, 0);
 		BlockCipher cipher = new AESLightEngine();
 		assert cipher.getBlockSize() == TAG_LENGTH;
@@ -308,7 +308,7 @@ class CryptoComponentImpl implements CryptoComponent {
 			int outputOff = salt.length + 4 + iv.length;
 			cipher.process(input, 0, input.length, output, outputOff);
 			return output;
-		} catch(GeneralSecurityException e) {
+		} catch (GeneralSecurityException e) {
 			throw new RuntimeException(e);
 		}
 	}
@@ -317,12 +317,12 @@ class CryptoComponentImpl implements CryptoComponent {
 		AuthenticatedCipher cipher = new AuthenticatedCipherImpl();
 		int macBytes = cipher.getMacBytes();
 		// The input contains the salt, iterations, IV, ciphertext and MAC
-		if(input.length < PBKDF_SALT_BYTES + 4 + STORAGE_IV_BYTES + macBytes)
+		if (input.length < PBKDF_SALT_BYTES + 4 + STORAGE_IV_BYTES + macBytes)
 			return null; // Invalid input
 		byte[] salt = new byte[PBKDF_SALT_BYTES];
 		System.arraycopy(input, 0, salt, 0, salt.length);
 		long iterations = ByteUtils.readUint32(input, salt.length);
-		if(iterations < 0 || iterations > Integer.MAX_VALUE)
+		if (iterations < 0 || iterations > Integer.MAX_VALUE)
 			return null; // Invalid iteration count
 		byte[] iv = new byte[STORAGE_IV_BYTES];
 		System.arraycopy(input, salt.length + 4, iv, 0, iv.length);
@@ -331,7 +331,7 @@ class CryptoComponentImpl implements CryptoComponent {
 		// Initialise the cipher
 		try {
 			cipher.init(false, key, iv);
-		} catch(GeneralSecurityException e) {
+		} catch (GeneralSecurityException e) {
 			throw new RuntimeException(e);
 		}
 		// Try to decrypt the ciphertext (may be invalid)
@@ -341,7 +341,7 @@ class CryptoComponentImpl implements CryptoComponent {
 			byte[] output = new byte[inputLen - macBytes];
 			cipher.process(input, inputOff, inputLen, output, 0);
 			return output;
-		} catch(GeneralSecurityException e) {
+		} catch (GeneralSecurityException e) {
 			return null; // Invalid ciphertext
 		}
 	}
@@ -351,18 +351,18 @@ class CryptoComponentImpl implements CryptoComponent {
 	private byte[] concatenationKdf(byte[]... inputs) {
 		// The output of the hash function must be long enough to use as a key
 		MessageDigest messageDigest = getMessageDigest();
-		if(messageDigest.getDigestLength() < SecretKey.LENGTH)
+		if (messageDigest.getDigestLength() < SecretKey.LENGTH)
 			throw new RuntimeException();
 		// Each input is length-prefixed - the length must fit in an
 		// unsigned 8-bit integer
-		for(byte[] input : inputs) {
-			if(input.length > 255) throw new IllegalArgumentException();
+		for (byte[] input : inputs) {
+			if (input.length > 255) throw new IllegalArgumentException();
 			messageDigest.update((byte) input.length);
 			messageDigest.update(input);
 		}
 		byte[] hash = messageDigest.digest();
 		// The output is the first SecretKey.LENGTH bytes of the hash
-		if(hash.length == SecretKey.LENGTH) return hash;
+		if (hash.length == SecretKey.LENGTH) return hash;
 		byte[] truncated = new byte[SecretKey.LENGTH];
 		System.arraycopy(hash, 0, truncated, 0, truncated.length);
 		return truncated;
@@ -371,10 +371,10 @@ class CryptoComponentImpl implements CryptoComponent {
 	// Key derivation function based on a PRF in counter mode - see
 	// NIST SP 800-108, section 5.1
 	private byte[] counterModeKdf(byte[] secret, byte[] label, long context) {
-		if(secret.length != SecretKey.LENGTH)
+		if (secret.length != SecretKey.LENGTH)
 			throw new IllegalArgumentException();
 		// The label must be null-terminated
-		if(label[label.length - 1] != '\0')
+		if (label[label.length - 1] != '\0')
 			throw new IllegalArgumentException();
 		// Initialise the PRF
 		Mac prf = new HMac(new SHA256Digest());
@@ -382,7 +382,7 @@ class CryptoComponentImpl implements CryptoComponent {
 		prf.init(k);
 		int macLength = prf.getMacSize();
 		// The output of the PRF must be long enough to use as a key
-		if(macLength < SecretKey.LENGTH) throw new RuntimeException();
+		if (macLength < SecretKey.LENGTH) throw new RuntimeException();
 		byte[] mac = new byte[macLength];
 		prf.update((byte) 0); // Counter
 		prf.update(label, 0, label.length); // Null-terminated
@@ -392,7 +392,7 @@ class CryptoComponentImpl implements CryptoComponent {
 		prf.update((byte) SecretKey.LENGTH); // Output length
 		prf.doFinal(mac, 0);
 		// The output is the first SecretKey.LENGTH bytes of the MAC
-		if(mac.length == SecretKey.LENGTH) return mac;
+		if (mac.length == SecretKey.LENGTH) return mac;
 		byte[] truncated = new byte[SecretKey.LENGTH];
 		System.arraycopy(mac, 0, truncated, 0, truncated.length);
 		return truncated;
@@ -414,9 +414,9 @@ class CryptoComponentImpl implements CryptoComponent {
 		List<Long> quickSamples = new ArrayList<Long>(PBKDF_SAMPLES);
 		List<Long> slowSamples = new ArrayList<Long>(PBKDF_SAMPLES);
 		long iterationNanos = 0, initNanos = 0;
-		while(iterationNanos <= 0 || initNanos <= 0) {
+		while (iterationNanos <= 0 || initNanos <= 0) {
 			// Sample the running time with one iteration and two iterations
-			for(int i = 0; i < PBKDF_SAMPLES; i++) {
+			for (int i = 0; i < PBKDF_SAMPLES; i++) {
 				quickSamples.add(sampleRunningTime(1));
 				slowSamples.add(sampleRunningTime(2));
 			}
@@ -425,16 +425,16 @@ class CryptoComponentImpl implements CryptoComponent {
 			long slowMedian = median(slowSamples);
 			iterationNanos = slowMedian - quickMedian;
 			initNanos = quickMedian - iterationNanos;
-			if(LOG.isLoggable(INFO)) {
+			if (LOG.isLoggable(INFO)) {
 				LOG.info("Init: " + initNanos + ", iteration: "
 						+ iterationNanos);
 			}
 		}
 		long targetNanos = targetMillis * 1000L * 1000L;
 		long iterations = (targetNanos - initNanos) / iterationNanos;
-		if(LOG.isLoggable(INFO)) LOG.info("Target iterations: " + iterations);
-		if(iterations < 1) return 1;
-		if(iterations > Integer.MAX_VALUE) return Integer.MAX_VALUE;
+		if (LOG.isLoggable(INFO)) LOG.info("Target iterations: " + iterations);
+		if (iterations < 1) return 1;
+		if (iterations > Integer.MAX_VALUE) return Integer.MAX_VALUE;
 		return (int) iterations;
 	}
 
@@ -452,9 +452,9 @@ class CryptoComponentImpl implements CryptoComponent {
 
 	private long median(List<Long> list) {
 		int size = list.size();
-		if(size == 0) throw new IllegalArgumentException();
+		if (size == 0) throw new IllegalArgumentException();
 		Collections.sort(list);
-		if(size % 2 == 1) return list.get(size / 2);
+		if (size % 2 == 1) return list.get(size / 2);
 		return list.get(size / 2 - 1) + list.get(size / 2) / 2;
 	}
 }
diff --git a/briar-core/src/org/briarproject/crypto/FortunaGenerator.java b/briar-core/src/org/briarproject/crypto/FortunaGenerator.java
index 4045db3ce1..885bd803b0 100644
--- a/briar-core/src/org/briarproject/crypto/FortunaGenerator.java
+++ b/briar-core/src/org/briarproject/crypto/FortunaGenerator.java
@@ -51,8 +51,8 @@ class FortunaGenerator {
 		synchLock.lock();
 		try {
 			counter[0]++;
-			for(int i = 0; counter[i] == 0; i++) {
-				if(i + 1 == BLOCK_BYTES)
+			for (int i = 0; counter[i] == 0; i++) {
+				if (i + 1 == BLOCK_BYTES)
 					throw new RuntimeException("Counter exhausted");
 				counter[i + 1]++;
 			}
@@ -76,31 +76,31 @@ class FortunaGenerator {
 		synchLock.lock();
 		try {
 			// Don't write more than the maximum number of bytes in one request
-			if(len > MAX_BYTES_PER_REQUEST) len = MAX_BYTES_PER_REQUEST;
+			if (len > MAX_BYTES_PER_REQUEST) len = MAX_BYTES_PER_REQUEST;
 			cipher.init(true, new KeyParameter(key));
 			// Generate full blocks directly into the output buffer
 			int fullBlocks = len / BLOCK_BYTES;
-			for(int i = 0; i < fullBlocks; i++) {
+			for (int i = 0; i < fullBlocks; i++) {
 				cipher.processBlock(counter, 0, dest, off + i * BLOCK_BYTES);
 				incrementCounter();
 			}
 			// Generate a partial block if needed
 			int done = fullBlocks * BLOCK_BYTES, remaining = len - done;
 			assert remaining < BLOCK_BYTES;
-			if(remaining > 0) {
+			if (remaining > 0) {
 				cipher.processBlock(counter, 0, buffer, 0);
 				incrementCounter();
 				// Copy the partial block to the output buffer and erase our copy
 				System.arraycopy(buffer, 0, dest, off + done, remaining);
-				for(int i = 0; i < BLOCK_BYTES; i++) buffer[i] = 0;
+				for (int i = 0; i < BLOCK_BYTES; i++) buffer[i] = 0;
 			}
 			// Generate a new key
-			for(int i = 0; i < KEY_BYTES / BLOCK_BYTES; i++) {
+			for (int i = 0; i < KEY_BYTES / BLOCK_BYTES; i++) {
 				cipher.processBlock(counter, 0, newKey, i * BLOCK_BYTES);
 				incrementCounter();
 			}
 			System.arraycopy(newKey, 0, key, 0, KEY_BYTES);
-			for(int i = 0; i < KEY_BYTES; i++) newKey[i] = 0;
+			for (int i = 0; i < KEY_BYTES; i++) newKey[i] = 0;
 			// Return the number of bytes written
 			return len;
 		} finally {
diff --git a/briar-core/src/org/briarproject/crypto/FortunaSecureRandom.java b/briar-core/src/org/briarproject/crypto/FortunaSecureRandom.java
index 01f7057e22..ce3aeeaf86 100644
--- a/briar-core/src/org/briarproject/crypto/FortunaSecureRandom.java
+++ b/briar-core/src/org/briarproject/crypto/FortunaSecureRandom.java
@@ -37,12 +37,12 @@ class FortunaSecureRandom extends SecureRandom {
 		SecureRandom r = new FortunaSecureRandom(seed);
 		byte[] output = new byte[16];
 		r.nextBytes(output);
-		if(!Arrays.equals(SELF_TEST_VECTOR_1, output)) return false;
+		if (!Arrays.equals(SELF_TEST_VECTOR_1, output)) return false;
 		r.nextBytes(output);
-		if(!Arrays.equals(SELF_TEST_VECTOR_2, output)) return false;
+		if (!Arrays.equals(SELF_TEST_VECTOR_2, output)) return false;
 		r.setSeed(seed);
 		r.nextBytes(output);
-		if(!Arrays.equals(SELF_TEST_VECTOR_3, output)) return false;
+		if (!Arrays.equals(SELF_TEST_VECTOR_3, output)) return false;
 		return true;
 	}
 
@@ -66,7 +66,7 @@ class FortunaSecureRandom extends SecureRandom {
 		@Override
 		protected void engineNextBytes(byte[] b) {
 			int offset = 0;
-			while(offset < b.length)
+			while (offset < b.length)
 				offset += generator.nextBytes(b, offset, b.length - offset);
 		}
 
diff --git a/briar-core/src/org/briarproject/crypto/FrameEncoder.java b/briar-core/src/org/briarproject/crypto/FrameEncoder.java
index 2cc6ffd58a..641e9a4664 100644
--- a/briar-core/src/org/briarproject/crypto/FrameEncoder.java
+++ b/briar-core/src/org/briarproject/crypto/FrameEncoder.java
@@ -10,39 +10,39 @@ import org.briarproject.util.ByteUtils;
 class FrameEncoder {
 
 	static void encodeIv(byte[] iv, long frameNumber, boolean header) {
-		if(iv.length < IV_LENGTH) throw new IllegalArgumentException();
-		if(frameNumber < 0 || frameNumber > MAX_32_BIT_UNSIGNED)
+		if (iv.length < IV_LENGTH) throw new IllegalArgumentException();
+		if (frameNumber < 0 || frameNumber > MAX_32_BIT_UNSIGNED)
 			throw new IllegalArgumentException();
 		ByteUtils.writeUint32(frameNumber, iv, 0);
-		if(header) iv[4] = 1;
+		if (header) iv[4] = 1;
 		else iv[4] = 0;
-		for(int i = 5; i < IV_LENGTH; i++) iv[i] = 0;
+		for (int i = 5; i < IV_LENGTH; i++) iv[i] = 0;
 	}
 
 	static void encodeHeader(byte[] header, boolean finalFrame,
 			int payloadLength, int paddingLength) {
-		if(header.length < HEADER_LENGTH) throw new IllegalArgumentException();
-		if(payloadLength < 0) throw new IllegalArgumentException();
-		if(paddingLength < 0) throw new IllegalArgumentException();
-		if(payloadLength + paddingLength > MAX_PAYLOAD_LENGTH)
+		if (header.length < HEADER_LENGTH) throw new IllegalArgumentException();
+		if (payloadLength < 0) throw new IllegalArgumentException();
+		if (paddingLength < 0) throw new IllegalArgumentException();
+		if (payloadLength + paddingLength > MAX_PAYLOAD_LENGTH)
 			throw new IllegalArgumentException();
 		ByteUtils.writeUint16(payloadLength, header, 0);
 		ByteUtils.writeUint16(paddingLength, header, 2);
-		if(finalFrame) header[0] |= 0x80;
+		if (finalFrame) header[0] |= 0x80;
 	}
 
 	static boolean isFinalFrame(byte[] header) {
-		if(header.length < HEADER_LENGTH) throw new IllegalArgumentException();
+		if (header.length < HEADER_LENGTH) throw new IllegalArgumentException();
 		return (header[0] & 0x80) == 0x80;
 	}
 
 	static int getPayloadLength(byte[] header) {
-		if(header.length < HEADER_LENGTH) throw new IllegalArgumentException();
+		if (header.length < HEADER_LENGTH) throw new IllegalArgumentException();
 		return ByteUtils.readUint16(header, 0) & 0x7FFF;
 	}
 
 	static int getPaddingLength(byte[] header) {
-		if(header.length < HEADER_LENGTH) throw new IllegalArgumentException();
+		if (header.length < HEADER_LENGTH) throw new IllegalArgumentException();
 		return ByteUtils.readUint16(header, 2);
 	}
 }
diff --git a/briar-core/src/org/briarproject/crypto/PasswordStrengthEstimatorImpl.java b/briar-core/src/org/briarproject/crypto/PasswordStrengthEstimatorImpl.java
index 1fd99f52bf..ca55efa07d 100644
--- a/briar-core/src/org/briarproject/crypto/PasswordStrengthEstimatorImpl.java
+++ b/briar-core/src/org/briarproject/crypto/PasswordStrengthEstimatorImpl.java
@@ -16,19 +16,19 @@ class PasswordStrengthEstimatorImpl implements PasswordStrengthEstimator {
 	public float estimateStrength(String password) {
 		HashSet<Character> unique = new HashSet<Character>();
 		int length = password.length();
-		for(int i = 0; i < length; i++) unique.add(password.charAt(i));
+		for (int i = 0; i < length; i++) unique.add(password.charAt(i));
 		boolean lower = false, upper = false, digit = false, other = false;
-		for(char c : unique) {
-			if(Character.isLowerCase(c)) lower = true;
-			else if(Character.isUpperCase(c)) upper = true;
-			else if(Character.isDigit(c)) digit = true;
+		for (char c : unique) {
+			if (Character.isLowerCase(c)) lower = true;
+			else if (Character.isUpperCase(c)) upper = true;
+			else if (Character.isDigit(c)) digit = true;
 			else other = true;
 		}
 		int alphabetSize = 0;
-		if(lower) alphabetSize += LOWER;
-		if(upper) alphabetSize += UPPER;
-		if(digit) alphabetSize += DIGIT;
-		if(other) alphabetSize += OTHER;
+		if (lower) alphabetSize += LOWER;
+		if (upper) alphabetSize += UPPER;
+		if (digit) alphabetSize += DIGIT;
+		if (other) alphabetSize += OTHER;
 		double score = Math.log(Math.pow(alphabetSize, unique.size()));
 		return Math.min(1, (float) (score / STRONG));
 	}
diff --git a/briar-core/src/org/briarproject/crypto/PseudoRandomImpl.java b/briar-core/src/org/briarproject/crypto/PseudoRandomImpl.java
index 9987062aca..f89475e482 100644
--- a/briar-core/src/org/briarproject/crypto/PseudoRandomImpl.java
+++ b/briar-core/src/org/briarproject/crypto/PseudoRandomImpl.java
@@ -17,7 +17,7 @@ class PseudoRandomImpl implements PseudoRandom {
 	public byte[] nextBytes(int length) {
 		byte[] b = new byte[length];
 		int offset = 0;
-		while(offset < length) offset += generator.nextBytes(b, offset, length);
+		while (offset < length) offset += generator.nextBytes(b, offset, length);
 		return b;
 	}
 }
diff --git a/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java b/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java
index d383138d98..99b3d2e727 100644
--- a/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java
+++ b/briar-core/src/org/briarproject/crypto/Sec1KeyParser.java
@@ -43,39 +43,39 @@ class Sec1KeyParser implements KeyParser {
 		// The validation procedure comes from SEC 1, section 3.2.2.1. Note
 		// that SEC 1 parameter names are used below, not RFC 5639 names
 		long now = System.currentTimeMillis();
-		if(encodedKey.length != publicKeyBytes)
+		if (encodedKey.length != publicKeyBytes)
 			throw new GeneralSecurityException();
 		// The first byte must be 0x04
-		if(encodedKey[0] != 4) throw new GeneralSecurityException();
+		if (encodedKey[0] != 4) throw new GeneralSecurityException();
 		// The x co-ordinate must be >= 0 and < p
 		byte[] xBytes = new byte[bytesPerInt];
 		System.arraycopy(encodedKey, 1, xBytes, 0, bytesPerInt);
 		BigInteger x = new BigInteger(1, xBytes); // Positive signum
-		if(x.compareTo(modulus) >= 0) throw new GeneralSecurityException();
+		if (x.compareTo(modulus) >= 0) throw new GeneralSecurityException();
 		// The y co-ordinate must be >= 0 and < p
 		byte[] yBytes = new byte[bytesPerInt];
 		System.arraycopy(encodedKey, 1 + bytesPerInt, yBytes, 0, bytesPerInt);
 		BigInteger y = new BigInteger(1, yBytes); // Positive signum
-		if(y.compareTo(modulus) >= 0) throw new GeneralSecurityException();
+		if (y.compareTo(modulus) >= 0) throw new GeneralSecurityException();
 		// Verify that y^2 == x^3 + ax + b (mod p)
 		ECCurve curve = params.getCurve();
 		BigInteger a = curve.getA().toBigInteger();
 		BigInteger b = curve.getB().toBigInteger();
 		BigInteger lhs = y.multiply(y).mod(modulus);
 		BigInteger rhs = x.multiply(x).add(a).multiply(x).add(b).mod(modulus);
-		if(!lhs.equals(rhs)) throw new GeneralSecurityException();
+		if (!lhs.equals(rhs)) throw new GeneralSecurityException();
 		// We know the point (x, y) is on the curve, so we can create the point
 		ECPoint pub = curve.createPoint(x, y).normalize();
 		// Verify that the point (x, y) is not the point at infinity
-		if(pub.isInfinity()) throw new GeneralSecurityException();
+		if (pub.isInfinity()) throw new GeneralSecurityException();
 		// Verify that the point (x, y) times n is the point at infinity
-		if(!pub.multiply(params.getN()).isInfinity())
+		if (!pub.multiply(params.getN()).isInfinity())
 			throw new GeneralSecurityException();
 		// Construct a public key from the point (x, y) and the params
 		ECPublicKeyParameters k = new ECPublicKeyParameters(pub, params);
 		PublicKey p = new Sec1PublicKey(k, keyBits);
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Parsing public key took " + duration + " ms");
 		return p;
 	}
@@ -83,17 +83,17 @@ class Sec1KeyParser implements KeyParser {
 	public PrivateKey parsePrivateKey(byte[] encodedKey)
 			throws GeneralSecurityException {
 		long now = System.currentTimeMillis();
-		if(encodedKey.length != privateKeyBytes)
+		if (encodedKey.length != privateKeyBytes)
 			throw new GeneralSecurityException();
 		BigInteger d = new BigInteger(1, encodedKey); // Positive signum
 		// Verify that the private value is < n
-		if(d.compareTo(params.getN()) >= 0)
+		if (d.compareTo(params.getN()) >= 0)
 			throw new GeneralSecurityException();
 		// Construct a private key from the private value and the params
 		ECPrivateKeyParameters k = new ECPrivateKeyParameters(d, params);
 		PrivateKey p = new Sec1PrivateKey(k, keyBits);
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Parsing private key took " + duration + " ms");
 		return p;
 	}
diff --git a/briar-core/src/org/briarproject/crypto/Sec1Utils.java b/briar-core/src/org/briarproject/crypto/Sec1Utils.java
index 23e1f86526..926bcbc69b 100644
--- a/briar-core/src/org/briarproject/crypto/Sec1Utils.java
+++ b/briar-core/src/org/briarproject/crypto/Sec1Utils.java
@@ -4,9 +4,9 @@ class Sec1Utils {
 
 	static void convertToFixedLength(byte[] src, byte[] dest, int destOff,
 			int destLen) {
-		if(src.length < destLen) {
+		if (src.length < destLen) {
 			int padding = destLen - src.length;
-			for(int i = destOff; i < destOff + padding; i++) dest[i] = 0;
+			for (int i = destOff; i < destOff + padding; i++) dest[i] = 0;
 			System.arraycopy(src, 0, dest, destOff + padding, src.length);
 		} else {
 			int srcOff = src.length - destLen;
diff --git a/briar-core/src/org/briarproject/crypto/SignatureImpl.java b/briar-core/src/org/briarproject/crypto/SignatureImpl.java
index 78501b18b2..dd79b8b4c9 100644
--- a/briar-core/src/org/briarproject/crypto/SignatureImpl.java
+++ b/briar-core/src/org/briarproject/crypto/SignatureImpl.java
@@ -35,13 +35,13 @@ class SignatureImpl implements Signature {
 	}
 
 	public void initSign(PrivateKey k) throws GeneralSecurityException {
-		if(!(k instanceof Sec1PrivateKey)) throw new GeneralSecurityException();
+		if (!(k instanceof Sec1PrivateKey)) throw new GeneralSecurityException();
 		ECPrivateKeyParameters priv = ((Sec1PrivateKey) k).getKey();
 		signer.init(true, new ParametersWithRandom(priv, secureRandom));
 	}
 
 	public void initVerify(PublicKey k) throws GeneralSecurityException {
-		if(!(k instanceof Sec1PublicKey)) throw new GeneralSecurityException();
+		if (!(k instanceof Sec1PublicKey)) throw new GeneralSecurityException();
 		ECPublicKeyParameters pub = ((Sec1PublicKey) k).getKey();
 		signer.init(false, pub);
 	}
@@ -62,7 +62,7 @@ class SignatureImpl implements Signature {
 		long now = System.currentTimeMillis();
 		byte[] signature = signer.generateSignature();
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Generating signature took " + duration + " ms");
 		return signature;
 	}
@@ -71,7 +71,7 @@ class SignatureImpl implements Signature {
 		long now = System.currentTimeMillis();
 		boolean valid = signer.verifySignature(signature);
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Verifying signature took " + duration + " ms");
 		return valid;
 	}
diff --git a/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java b/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java
index 3e3e240552..1cad6d2184 100644
--- a/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java
+++ b/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java
@@ -38,14 +38,14 @@ class StreamDecrypterImpl implements StreamDecrypter {
 	}
 
 	public int readFrame(byte[] payload) throws IOException {
-		if(payload.length < MAX_PAYLOAD_LENGTH)
+		if (payload.length < MAX_PAYLOAD_LENGTH)
 			throw new IllegalArgumentException();
-		if(finalFrame) return -1;
+		if (finalFrame) return -1;
 		// Read the header
 		int offset = 0;
-		while(offset < HEADER_LENGTH) {
+		while (offset < HEADER_LENGTH) {
 			int read = in.read(ciphertext, offset, HEADER_LENGTH - offset);
-			if(read == -1) throw new EOFException();
+			if (read == -1) throw new EOFException();
 			offset += read;
 		}
 		// Decrypt and authenticate the header
@@ -54,23 +54,23 @@ class StreamDecrypterImpl implements StreamDecrypter {
 			frameCipher.init(false, frameKey, iv);
 			int decrypted = frameCipher.process(ciphertext, 0, HEADER_LENGTH,
 					header, 0);
-			if(decrypted != HEADER_LENGTH - MAC_LENGTH)
+			if (decrypted != HEADER_LENGTH - MAC_LENGTH)
 				throw new RuntimeException();
-		} catch(GeneralSecurityException e) {
+		} catch (GeneralSecurityException e) {
 			throw new FormatException();
 		}
 		// Decode and validate the header
 		finalFrame = FrameEncoder.isFinalFrame(header);
 		int payloadLength = FrameEncoder.getPayloadLength(header);
 		int paddingLength = FrameEncoder.getPaddingLength(header);
-		if(payloadLength + paddingLength > MAX_PAYLOAD_LENGTH)
+		if (payloadLength + paddingLength > MAX_PAYLOAD_LENGTH)
 			throw new FormatException();
 		// Read the payload and padding
 		int frameLength = HEADER_LENGTH + payloadLength + paddingLength
 				+ MAC_LENGTH;
-		while(offset < frameLength) {
+		while (offset < frameLength) {
 			int read = in.read(ciphertext, offset, frameLength - offset);
-			if(read == -1) throw new EOFException();
+			if (read == -1) throw new EOFException();
 			offset += read;
 		}
 		// Decrypt and authenticate the payload and padding
@@ -79,14 +79,14 @@ class StreamDecrypterImpl implements StreamDecrypter {
 			frameCipher.init(false, frameKey, iv);
 			int decrypted = frameCipher.process(ciphertext, HEADER_LENGTH,
 					payloadLength + paddingLength + MAC_LENGTH, payload, 0);
-			if(decrypted != payloadLength + paddingLength)
+			if (decrypted != payloadLength + paddingLength)
 				throw new RuntimeException();
-		} catch(GeneralSecurityException e) {
+		} catch (GeneralSecurityException e) {
 			throw new FormatException();
 		}
 		// If there's any padding it must be all zeroes
-		for(int i = 0; i < paddingLength; i++)
-			if(payload[payloadLength + i] != 0) throw new FormatException();
+		for (int i = 0; i < paddingLength; i++)
+			if (payload[payloadLength + i] != 0) throw new FormatException();
 		frameNumber++;
 		return payloadLength;
 	}
diff --git a/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java b/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java
index 118648a2b7..7d9f71b7cf 100644
--- a/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java
+++ b/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java
@@ -39,12 +39,12 @@ class StreamEncrypterImpl implements StreamEncrypter {
 
 	public void writeFrame(byte[] payload, int payloadLength,
 			int paddingLength, boolean finalFrame) throws IOException {
-		if(payloadLength + paddingLength > MAX_PAYLOAD_LENGTH)
+		if (payloadLength + paddingLength > MAX_PAYLOAD_LENGTH)
 			throw new IllegalArgumentException();
 		// Don't allow the frame counter to wrap
-		if(frameNumber > MAX_32_BIT_UNSIGNED) throw new IOException();
+		if (frameNumber > MAX_32_BIT_UNSIGNED) throw new IOException();
 		// Write the tag if required
-		if(writeTag) {
+		if (writeTag) {
 			out.write(tag, 0, tag.length);
 			writeTag = false;
 		}
@@ -57,13 +57,13 @@ class StreamEncrypterImpl implements StreamEncrypter {
 			frameCipher.init(true, frameKey, iv);
 			int encrypted = frameCipher.process(plaintext, 0,
 					HEADER_LENGTH - MAC_LENGTH, ciphertext, 0);
-			if(encrypted != HEADER_LENGTH) throw new RuntimeException();
-		} catch(GeneralSecurityException badCipher) {
+			if (encrypted != HEADER_LENGTH) throw new RuntimeException();
+		} catch (GeneralSecurityException badCipher) {
 			throw new RuntimeException(badCipher);
 		}
 		// Combine the payload and padding
 		System.arraycopy(payload, 0, plaintext, HEADER_LENGTH, payloadLength);
-		for(int i = 0; i < paddingLength; i++)
+		for (int i = 0; i < paddingLength; i++)
 			plaintext[HEADER_LENGTH + payloadLength + i] = 0;
 		// Encrypt and authenticate the payload and padding
 		FrameEncoder.encodeIv(iv, frameNumber, false);
@@ -71,9 +71,9 @@ class StreamEncrypterImpl implements StreamEncrypter {
 			frameCipher.init(true, frameKey, iv);
 			int encrypted = frameCipher.process(plaintext, HEADER_LENGTH,
 					payloadLength + paddingLength, ciphertext, HEADER_LENGTH);
-			if(encrypted != payloadLength + paddingLength + MAC_LENGTH)
+			if (encrypted != payloadLength + paddingLength + MAC_LENGTH)
 				throw new RuntimeException();
-		} catch(GeneralSecurityException badCipher) {
+		} catch (GeneralSecurityException badCipher) {
 			throw new RuntimeException(badCipher);
 		}
 		// Write the frame
@@ -84,7 +84,7 @@ class StreamEncrypterImpl implements StreamEncrypter {
 
 	public void flush() throws IOException {
 		// Write the tag if required
-		if(writeTag) {
+		if (writeTag) {
 			out.write(tag, 0, tag.length);
 			writeTag = false;
 		}
diff --git a/briar-core/src/org/briarproject/data/ReaderImpl.java b/briar-core/src/org/briarproject/data/ReaderImpl.java
index 420ff25ed9..db902ef831 100644
--- a/briar-core/src/org/briarproject/data/ReaderImpl.java
+++ b/briar-core/src/org/briarproject/data/ReaderImpl.java
@@ -48,7 +48,7 @@ class ReaderImpl implements Reader {
 		assert !hasLookahead;
 		// Read a lookahead byte
 		int i = in.read();
-		if(i == -1) {
+		if (i == -1) {
 			eof = true;
 			return;
 		}
@@ -58,49 +58,49 @@ class ReaderImpl implements Reader {
 
 	private void consumeLookahead() throws IOException {
 		assert hasLookahead;
-		for(Consumer c : consumers) c.write(next);
+		for (Consumer c : consumers) c.write(next);
 		hasLookahead = false;
 	}
 
 	private void readIntoBuffer(byte[] b, int length, boolean consume)
 			throws IOException {
 		int offset = 0;
-		while(offset < length) {
+		while (offset < length) {
 			int read = in.read(b, offset, length - offset);
-			if(read == -1) throw new FormatException();
+			if (read == -1) throw new FormatException();
 			offset += read;
 		}
-		if(consume) for(Consumer c : consumers) c.write(b, 0, length);
+		if (consume) for (Consumer c : consumers) c.write(b, 0, length);
 	}
 
 	private void readIntoBuffer(int length, boolean consume)
 			throws IOException {
-		if(buf.length < length) buf = new byte[length];
+		if (buf.length < length) buf = new byte[length];
 		readIntoBuffer(buf, length, consume);
 	}
 
 	private void skip(int length) throws IOException {
-		while(length > 0) {
+		while (length > 0) {
 			int read = in.read(buf, 0, Math.min(length, buf.length));
-			if(read == -1) throw new FormatException();
+			if (read == -1) throw new FormatException();
 			length -= read;
 		}
 	}
 
 	private void skipObject() throws IOException {
-		if(hasBoolean()) skipBoolean();
-		else if(hasInteger()) skipInteger();
-		else if(hasFloat()) skipFloat();
-		else if(hasString()) skipString();
-		else if(hasRaw()) skipRaw();
-		else if(hasList()) skipList();
-		else if(hasMap()) skipMap();
-		else if(hasNull()) skipNull();
+		if (hasBoolean()) skipBoolean();
+		else if (hasInteger()) skipInteger();
+		else if (hasFloat()) skipFloat();
+		else if (hasString()) skipString();
+		else if (hasRaw()) skipRaw();
+		else if (hasList()) skipList();
+		else if (hasMap()) skipMap();
+		else if (hasNull()) skipNull();
 		else throw new FormatException();
 	}
 
 	public boolean eof() throws IOException {
-		if(!hasLookahead) readLookahead();
+		if (!hasLookahead) readLookahead();
 		return eof;
 	}
 
@@ -113,56 +113,56 @@ class ReaderImpl implements Reader {
 	}
 
 	public void removeConsumer(Consumer c) {
-		if(!consumers.remove(c)) throw new IllegalArgumentException();
+		if (!consumers.remove(c)) throw new IllegalArgumentException();
 	}
 
 	public boolean hasNull() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == NULL;
 	}
 
 	public void readNull() throws IOException {
-		if(!hasNull()) throw new FormatException();
+		if (!hasNull()) throw new FormatException();
 		consumeLookahead();
 	}
 
 	public void skipNull() throws IOException {
-		if(!hasNull()) throw new FormatException();
+		if (!hasNull()) throw new FormatException();
 		hasLookahead = false;
 	}
 
 	public boolean hasBoolean() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == FALSE || next == TRUE;
 	}
 
 	public boolean readBoolean() throws IOException {
-		if(!hasBoolean()) throw new FormatException();
+		if (!hasBoolean()) throw new FormatException();
 		boolean bool = next == TRUE;
 		consumeLookahead();
 		return bool;
 	}
 
 	public void skipBoolean() throws IOException {
-		if(!hasBoolean()) throw new FormatException();
+		if (!hasBoolean()) throw new FormatException();
 		hasLookahead = false;
 	}
 
 	public boolean hasInteger() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == INT_8 || next == INT_16 || next == INT_32 ||
 				next == INT_64;
 	}
 
 	public long readInteger() throws IOException {
-		if(!hasInteger()) throw new FormatException();
+		if (!hasInteger()) throw new FormatException();
 		consumeLookahead();
-		if(next == INT_8) return readInt8(true);
-		if(next == INT_16) return readInt16(true);
-		if(next == INT_32) return readInt32(true);
+		if (next == INT_8) return readInt8(true);
+		if (next == INT_16) return readInt16(true);
+		if (next == INT_32) return readInt32(true);
 		return readInt64(true);
 	}
 
@@ -174,7 +174,7 @@ class ReaderImpl implements Reader {
 	private short readInt16(boolean consume) throws IOException {
 		readIntoBuffer(2, consume);
 		short value = (short) (((buf[0] & 0xFF) << 8) + (buf[1] & 0xFF));
-		if(value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
+		if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
 			throw new FormatException();
 		return value;
 	}
@@ -182,8 +182,8 @@ class ReaderImpl implements Reader {
 	private int readInt32(boolean consume) throws IOException {
 		readIntoBuffer(4, consume);
 		int value = 0;
-		for(int i = 0; i < 4; i++) value |= (buf[i] & 0xFF) << (24 - i * 8);
-		if(value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
+		for (int i = 0; i < 4; i++) value |= (buf[i] & 0xFF) << (24 - i * 8);
+		if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
 			throw new FormatException();
 		return value;
 	}
@@ -191,113 +191,113 @@ class ReaderImpl implements Reader {
 	private long readInt64(boolean consume) throws IOException {
 		readIntoBuffer(8, consume);
 		long value = 0;
-		for(int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
-		if(value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE)
+		for (int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
+		if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE)
 			throw new FormatException();
 		return value;
 	}
 
 	public void skipInteger() throws IOException {
-		if(!hasInteger()) throw new FormatException();
-		if(next == INT_8) skip(1);
-		else if(next == INT_16) skip(2);
-		else if(next == INT_32) skip(4);
+		if (!hasInteger()) throw new FormatException();
+		if (next == INT_8) skip(1);
+		else if (next == INT_16) skip(2);
+		else if (next == INT_32) skip(4);
 		else skip(8);
 		hasLookahead = false;
 	}
 
 	public boolean hasFloat() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == FLOAT_64;
 	}
 
 	public double readFloat() throws IOException {
-		if(!hasFloat()) throw new FormatException();
+		if (!hasFloat()) throw new FormatException();
 		consumeLookahead();
 		readIntoBuffer(8, true);
 		long value = 0;
-		for(int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
+		for (int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
 		return Double.longBitsToDouble(value);
 	}
 
 	public void skipFloat() throws IOException {
-		if(!hasFloat()) throw new FormatException();
+		if (!hasFloat()) throw new FormatException();
 		skip(8);
 		hasLookahead = false;
 	}
 
 	public boolean hasString() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == STRING_8 || next == STRING_16 || next == STRING_32;
 	}
 
 	public String readString(int maxLength) throws IOException {
-		if(!hasString()) throw new FormatException();
+		if (!hasString()) throw new FormatException();
 		consumeLookahead();
 		int length = readStringLength(true);
-		if(length < 0 || length > maxLength) throw new FormatException();
-		if(length == 0) return "";
+		if (length < 0 || length > maxLength) throw new FormatException();
+		if (length == 0) return "";
 		readIntoBuffer(length, true);
 		return new String(buf, 0, length, "UTF-8");
 	}
 
 	private int readStringLength(boolean consume) throws IOException {
-		if(next == STRING_8) return readInt8(consume);
-		if(next == STRING_16) return readInt16(consume);
-		if(next == STRING_32) return readInt32(consume);
+		if (next == STRING_8) return readInt8(consume);
+		if (next == STRING_16) return readInt16(consume);
+		if (next == STRING_32) return readInt32(consume);
 		throw new FormatException();
 	}
 
 	public void skipString() throws IOException {
-		if(!hasString()) throw new FormatException();
+		if (!hasString()) throw new FormatException();
 		int length = readStringLength(false);
-		if(length < 0) throw new FormatException();
+		if (length < 0) throw new FormatException();
 		skip(length);
 		hasLookahead = false;
 	}
 
 	public boolean hasRaw() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == RAW_8 || next == RAW_16 || next == RAW_32;
 	}
 
 	public byte[] readRaw(int maxLength) throws IOException {
-		if(!hasRaw()) throw new FormatException();
+		if (!hasRaw()) throw new FormatException();
 		consumeLookahead();
 		int length = readRawLength(true);
-		if(length < 0 || length > maxLength) throw new FormatException();
-		if(length == 0) return EMPTY_BUFFER;
+		if (length < 0 || length > maxLength) throw new FormatException();
+		if (length == 0) return EMPTY_BUFFER;
 		byte[] b = new byte[length];
 		readIntoBuffer(b, length, true);
 		return b;
 	}
 
 	private int readRawLength(boolean consume) throws IOException {
-		if(next == RAW_8) return readInt8(consume);
-		if(next == RAW_16) return readInt16(consume);
-		if(next == RAW_32) return readInt32(consume);
+		if (next == RAW_8) return readInt8(consume);
+		if (next == RAW_16) return readInt16(consume);
+		if (next == RAW_32) return readInt32(consume);
 		throw new FormatException();
 	}
 
 	public void skipRaw() throws IOException {
-		if(!hasRaw()) throw new FormatException();
+		if (!hasRaw()) throw new FormatException();
 		int length = readRawLength(false);
-		if(length < 0) throw new FormatException();
+		if (length < 0) throw new FormatException();
 		skip(length);
 		hasLookahead = false;
 	}
 
 	public boolean hasList() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == LIST;
 	}
 
 	public void readListStart() throws IOException {
-		if(!hasList()) throw new FormatException();
+		if (!hasList()) throw new FormatException();
 		consumeLookahead();
 	}
 
@@ -306,8 +306,8 @@ class ReaderImpl implements Reader {
 	}
 
 	private boolean hasEnd() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == END;
 	}
 
@@ -316,25 +316,25 @@ class ReaderImpl implements Reader {
 	}
 
 	private void readEnd() throws IOException {
-		if(!hasEnd()) throw new FormatException();
+		if (!hasEnd()) throw new FormatException();
 		consumeLookahead();
 	}
 
 	public void skipList() throws IOException {
-		if(!hasList()) throw new FormatException();
+		if (!hasList()) throw new FormatException();
 		hasLookahead = false;
-		while(!hasListEnd()) skipObject();
+		while (!hasListEnd()) skipObject();
 		hasLookahead = false;
 	}
 
 	public boolean hasMap() throws IOException {
-		if(!hasLookahead) readLookahead();
-		if(eof) return false;
+		if (!hasLookahead) readLookahead();
+		if (eof) return false;
 		return next == MAP;
 	}
 
 	public void readMapStart() throws IOException {
-		if(!hasMap()) throw new FormatException();
+		if (!hasMap()) throw new FormatException();
 		consumeLookahead();
 	}
 
@@ -347,9 +347,9 @@ class ReaderImpl implements Reader {
 	}
 
 	public void skipMap() throws IOException {
-		if(!hasMap()) throw new FormatException();
+		if (!hasMap()) throw new FormatException();
 		hasLookahead = false;
-		while(!hasMapEnd()) {
+		while (!hasMapEnd()) {
 			skipObject();
 			skipObject();
 		}
diff --git a/briar-core/src/org/briarproject/data/WriterImpl.java b/briar-core/src/org/briarproject/data/WriterImpl.java
index e178bff9dd..3f51be2769 100644
--- a/briar-core/src/org/briarproject/data/WriterImpl.java
+++ b/briar-core/src/org/briarproject/data/WriterImpl.java
@@ -53,7 +53,7 @@ class WriterImpl implements Writer {
 	}
 
 	public void removeConsumer(Consumer c) {
-		if(!consumers.remove(c)) throw new IllegalArgumentException();
+		if (!consumers.remove(c)) throw new IllegalArgumentException();
 	}
 
 	public void writeNull() throws IOException {
@@ -61,18 +61,18 @@ class WriterImpl implements Writer {
 	}
 
 	public void writeBoolean(boolean b) throws IOException {
-		if(b) write(TRUE);
+		if (b) write(TRUE);
 		else write(FALSE);
 	}
 
 	public void writeInteger(long i) throws IOException {
-		if(i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
+		if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
 			write(INT_8);
 			write((byte) i);
-		} else if(i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
+		} else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
 			write(INT_16);
 			writeInt16((short) i);
-		} else if(i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE) {
+		} else if (i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE) {
 			write(INT_32);
 			writeInt32((int) i);
 		} else {
@@ -111,10 +111,10 @@ class WriterImpl implements Writer {
 
 	public void writeString(String s) throws IOException {
 		byte[] b = s.getBytes("UTF-8");
-		if(b.length <= Byte.MAX_VALUE) {
+		if (b.length <= Byte.MAX_VALUE) {
 			write(STRING_8);
 			write((byte) b.length);
-		} else if(b.length <= Short.MAX_VALUE) {
+		} else if (b.length <= Short.MAX_VALUE) {
 			write(STRING_16);
 			writeInt16((short) b.length);
 		} else {
@@ -125,10 +125,10 @@ class WriterImpl implements Writer {
 	}
 
 	public void writeRaw(byte[] b) throws IOException {
-		if(b.length <= Byte.MAX_VALUE) {
+		if (b.length <= Byte.MAX_VALUE) {
 			write(RAW_8);
 			write((byte) b.length);
-		} else if(b.length <= Short.MAX_VALUE) {
+		} else if (b.length <= Short.MAX_VALUE) {
 			write(RAW_16);
 			writeInt16((short) b.length);
 		} else {
@@ -140,24 +140,24 @@ class WriterImpl implements Writer {
 
 	public void writeList(Collection<?> c) throws IOException {
 		write(LIST);
-		for(Object o : c) writeObject(o);
+		for (Object o : c) writeObject(o);
 		write(END);
 	}
 
 	private void writeObject(Object o) throws IOException {
-		if(o instanceof Boolean) writeBoolean((Boolean) o);
-		else if(o instanceof Byte) writeInteger((Byte) o);
-		else if(o instanceof Short) writeInteger((Short) o);
-		else if(o instanceof Integer) writeInteger((Integer) o);
-		else if(o instanceof Long) writeInteger((Long) o);
-		else if(o instanceof Float) writeFloat((Float) o);
-		else if(o instanceof Double) writeFloat((Double) o);
-		else if(o instanceof String) writeString((String) o);
-		else if(o instanceof byte[]) writeRaw((byte[]) o);
-		else if(o instanceof Bytes) writeRaw(((Bytes) o).getBytes());
-		else if(o instanceof List<?>) writeList((List<?>) o);
-		else if(o instanceof Map<?, ?>) writeMap((Map<?, ?>) o);
-		else if(o == null) writeNull();
+		if (o instanceof Boolean) writeBoolean((Boolean) o);
+		else if (o instanceof Byte) writeInteger((Byte) o);
+		else if (o instanceof Short) writeInteger((Short) o);
+		else if (o instanceof Integer) writeInteger((Integer) o);
+		else if (o instanceof Long) writeInteger((Long) o);
+		else if (o instanceof Float) writeFloat((Float) o);
+		else if (o instanceof Double) writeFloat((Double) o);
+		else if (o instanceof String) writeString((String) o);
+		else if (o instanceof byte[]) writeRaw((byte[]) o);
+		else if (o instanceof Bytes) writeRaw(((Bytes) o).getBytes());
+		else if (o instanceof List<?>) writeList((List<?>) o);
+		else if (o instanceof Map<?, ?>) writeMap((Map<?, ?>) o);
+		else if (o == null) writeNull();
 		else throw new IllegalStateException();
 	}
 
@@ -171,7 +171,7 @@ class WriterImpl implements Writer {
 
 	public void writeMap(Map<?, ?> m) throws IOException {
 		write(MAP);
-		for(Entry<?, ?> e : m.entrySet()) {
+		for (Entry<?, ?> e : m.entrySet()) {
 			writeObject(e.getKey());
 			writeObject(e.getValue());
 		}
@@ -188,11 +188,11 @@ class WriterImpl implements Writer {
 
 	private void write(byte b) throws IOException {
 		out.write(b);
-		for(Consumer c : consumers) c.write(b);
+		for (Consumer c : consumers) c.write(b);
 	}
 
 	private void write(byte[] b) throws IOException {
 		out.write(b);
-		for(Consumer c : consumers) c.write(b, 0, b.length);
+		for (Consumer c : consumers) c.write(b, 0, b.length);
 	}
 }
diff --git a/briar-core/src/org/briarproject/db/DatabaseCleanerImpl.java b/briar-core/src/org/briarproject/db/DatabaseCleanerImpl.java
index b2d9cce65e..d286ba201a 100644
--- a/briar-core/src/org/briarproject/db/DatabaseCleanerImpl.java
+++ b/briar-core/src/org/briarproject/db/DatabaseCleanerImpl.java
@@ -35,19 +35,19 @@ class DatabaseCleanerImpl extends TimerTask implements DatabaseCleaner {
 	}
 
 	public void run() {
-		if(callback == null) throw new IllegalStateException();
+		if (callback == null) throw new IllegalStateException();
 		try {
-			if(callback.shouldCheckFreeSpace()) {
+			if (callback.shouldCheckFreeSpace()) {
 				LOG.info("Checking free space");
 				callback.checkFreeSpaceAndClean();
 			}
-		} catch(DbClosedException e) {
+		} catch (DbClosedException e) {
 			LOG.info("Database closed, exiting");
-		} catch(DbException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (DbException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			throw new Error(e); // Kill the application
-		} catch(RuntimeException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (RuntimeException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			throw new Error(e); // Kill the application
 		}
 	}
diff --git a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
index e4ed61e501..32467764eb 100644
--- a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
+++ b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
@@ -117,11 +117,11 @@ DatabaseCleaner.Callback {
 				try {
 					shutdownHandle = -1;
 					close();
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				} finally {
 					lock.writeLock().unlock();
@@ -130,7 +130,7 @@ DatabaseCleaner.Callback {
 		};
 		lock.writeLock().lock();
 		try {
-			if(open) throw new IllegalStateException();
+			if (open) throw new IllegalStateException();
 			open = true;
 			boolean reopened = db.open();
 			cleaner.startCleaning(this, MS_BETWEEN_SWEEPS);
@@ -144,9 +144,9 @@ DatabaseCleaner.Callback {
 	public void close() throws DbException, IOException {
 		lock.writeLock().lock();
 		try {
-			if(!open) return;
+			if (!open) return;
 			open = false;
-			if(shutdownHandle != -1)
+			if (shutdownHandle != -1)
 				shutdown.removeShutdownHook(shutdownHandle);
 			cleaner.stopCleaning();
 			db.close();
@@ -162,13 +162,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(db.containsContact(txn, remote.getId()))
+				if (db.containsContact(txn, remote.getId()))
 					throw new ContactExistsException();
-				if(!db.containsLocalAuthor(txn, local))
+				if (!db.containsLocalAuthor(txn, local))
 					throw new NoSuchLocalAuthorException();
 				c = db.addContact(txn, remote, local);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -184,13 +184,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, ep.getContactId()))
+				if (!db.containsContact(txn, ep.getContactId()))
 					throw new NoSuchContactException();
-				if(!db.containsTransport(txn, ep.getTransportId()))
+				if (!db.containsTransport(txn, ep.getTransportId()))
 					throw new NoSuchTransportException();
 				db.addEndpoint(txn, ep);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -205,17 +205,17 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsGroup(txn, g.getId()))
+				if (!db.containsGroup(txn, g.getId()))
 					added = db.addGroup(txn, g);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(added) eventBus.broadcast(new SubscriptionAddedEvent(g));
+		if (added) eventBus.broadcast(new SubscriptionAddedEvent(g));
 		return added;
 	}
 
@@ -224,11 +224,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(db.containsLocalAuthor(txn, a.getId()))
+				if (db.containsLocalAuthor(txn, a.getId()))
 					throw new LocalAuthorExistsException();
 				db.addLocalAuthor(txn, a);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -246,16 +246,16 @@ DatabaseCleaner.Callback {
 			try {
 				duplicate = db.containsMessage(txn, m.getId());
 				subscribed = db.containsGroup(txn, m.getGroup().getId());
-				if(!duplicate && subscribed) addMessage(txn, m, null);
+				if (!duplicate && subscribed) addMessage(txn, m, null);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(!duplicate && subscribed)
+		if (!duplicate && subscribed)
 			eventBus.broadcast(new MessageAddedEvent(m.getGroup(), null));
 	}
 
@@ -268,7 +268,7 @@ DatabaseCleaner.Callback {
 	 */
 	private void addMessage(T txn, Message m, ContactId sender)
 			throws DbException {
-		if(sender == null) {
+		if (sender == null) {
 			db.addMessage(txn, m, true);
 			db.setReadFlag(txn, m.getId(), true);
 		} else {
@@ -277,13 +277,13 @@ DatabaseCleaner.Callback {
 		Group g = m.getGroup();
 		Collection<ContactId> visibility = db.getVisibility(txn, g.getId());
 		visibility = new HashSet<ContactId>(visibility);
-		for(ContactId c : db.getContactIds(txn)) {
-			if(visibility.contains(c)) {
+		for (ContactId c : db.getContactIds(txn)) {
+			if (visibility.contains(c)) {
 				boolean offered = db.removeOfferedMessage(txn, c, m.getId());
 				boolean seen = offered || c.equals(sender);
 				db.addStatus(txn, c, m.getId(), offered, seen);
 			} else {
-				if(c.equals(sender)) throw new IllegalStateException();
+				if (c.equals(sender)) throw new IllegalStateException();
 				db.addStatus(txn, c, m.getId(), false, false);
 			}
 		}
@@ -297,14 +297,14 @@ DatabaseCleaner.Callback {
 			try {
 				Collection<TemporarySecret> relevant =
 						new ArrayList<TemporarySecret>();
-				for(TemporarySecret s : secrets) {
-					if(db.containsContact(txn, s.getContactId()))
-						if(db.containsTransport(txn, s.getTransportId()))
+				for (TemporarySecret s : secrets) {
+					if (db.containsContact(txn, s.getContactId()))
+						if (db.containsTransport(txn, s.getTransportId()))
 							relevant.add(s);
 				}
-				if(!secrets.isEmpty()) db.addSecrets(txn, relevant);
+				if (!secrets.isEmpty()) db.addSecrets(txn, relevant);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -322,14 +322,14 @@ DatabaseCleaner.Callback {
 			try {
 				added = db.addTransport(txn, t, maxLatency);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(added) eventBus.broadcast(new TransportAddedEvent(t, maxLatency));
+		if (added) eventBus.broadcast(new TransportAddedEvent(t, maxLatency));
 		return added;
 	}
 
@@ -339,19 +339,19 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				ids = db.getMessagesToAck(txn, c, maxMessages);
-				if(!ids.isEmpty()) db.lowerAckFlag(txn, c, ids);
+				if (!ids.isEmpty()) db.lowerAckFlag(txn, c, ids);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(ids.isEmpty()) return null;
+		if (ids.isEmpty()) return null;
 		return new Ack(ids);
 	}
 
@@ -363,23 +363,23 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				ids = db.getMessagesToSend(txn, c, maxLength);
-				for(MessageId m : ids) {
+				for (MessageId m : ids) {
 					messages.add(db.getRawMessage(txn, m));
 					db.updateExpiryTime(txn, c, m, maxLatency);
 				}
-				if(!ids.isEmpty()) db.lowerRequestedFlag(txn, c, ids);
+				if (!ids.isEmpty()) db.lowerRequestedFlag(txn, c, ids);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(messages.isEmpty()) return null;
+		if (messages.isEmpty()) return null;
 		return Collections.unmodifiableList(messages);
 	}
 
@@ -390,20 +390,20 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				ids = db.getMessagesToOffer(txn, c, maxMessages);
-				for(MessageId m : ids)
+				for (MessageId m : ids)
 					db.updateExpiryTime(txn, c, m, maxLatency);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(ids.isEmpty()) return null;
+		if (ids.isEmpty()) return null;
 		return new Offer(ids);
 	}
 
@@ -414,19 +414,19 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				ids = db.getMessagesToRequest(txn, c, maxMessages);
-				if(!ids.isEmpty()) db.removeOfferedMessages(txn, c, ids);
+				if (!ids.isEmpty()) db.removeOfferedMessages(txn, c, ids);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(ids.isEmpty()) return null;
+		if (ids.isEmpty()) return null;
 		return new Request(ids);
 	}
 
@@ -438,23 +438,23 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				ids = db.getRequestedMessagesToSend(txn, c, maxLength);
-				for(MessageId m : ids) {
+				for (MessageId m : ids) {
 					messages.add(db.getRawMessage(txn, m));
 					db.updateExpiryTime(txn, c, m, maxLatency);
 				}
-				if(!ids.isEmpty()) db.lowerRequestedFlag(txn, c, ids);
+				if (!ids.isEmpty()) db.lowerRequestedFlag(txn, c, ids);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(messages.isEmpty()) return null;
+		if (messages.isEmpty()) return null;
 		return Collections.unmodifiableList(messages);
 	}
 
@@ -463,12 +463,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				RetentionAck a = db.getRetentionAck(txn, c);
 				db.commitTransaction(txn);
 				return a;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -483,12 +483,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				RetentionUpdate u = db.getRetentionUpdate(txn, c, maxLatency);
 				db.commitTransaction(txn);
 				return u;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -503,12 +503,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				SubscriptionAck a = db.getSubscriptionAck(txn, c);
 				db.commitTransaction(txn);
 				return a;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -523,13 +523,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				SubscriptionUpdate u =
 						db.getSubscriptionUpdate(txn, c, maxLatency);
 				db.commitTransaction(txn);
 				return u;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -544,12 +544,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				Collection<TransportAck> acks = db.getTransportAcks(txn, c);
 				db.commitTransaction(txn);
 				return acks;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -564,13 +564,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				Collection<TransportUpdate> updates =
 						db.getTransportUpdates(txn, c, maxLatency);
 				db.commitTransaction(txn);
 				return updates;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -587,7 +587,7 @@ DatabaseCleaner.Callback {
 				Collection<Group> groups = db.getAvailableGroups(txn);
 				db.commitTransaction(txn);
 				return groups;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -601,12 +601,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsTransport(txn, t))
+				if (!db.containsTransport(txn, t))
 					throw new NoSuchTransportException();
 				TransportConfig config = db.getConfig(txn, t);
 				db.commitTransaction(txn);
 				return config;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -620,12 +620,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				Contact contact = db.getContact(txn, c);
 				db.commitTransaction(txn);
 				return contact;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -642,7 +642,7 @@ DatabaseCleaner.Callback {
 				Collection<Contact> contacts = db.getContacts(txn);
 				db.commitTransaction(txn);
 				return contacts;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -656,12 +656,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsGroup(txn, g))
+				if (!db.containsGroup(txn, g))
 					throw new NoSuchSubscriptionException();
 				Group group = db.getGroup(txn, g);
 				db.commitTransaction(txn);
 				return group;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -678,7 +678,7 @@ DatabaseCleaner.Callback {
 				Collection<Group> groups = db.getGroups(txn);
 				db.commitTransaction(txn);
 				return groups;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -692,12 +692,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				GroupId inbox = db.getInboxGroupId(txn, c);
 				db.commitTransaction(txn);
 				return inbox;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -712,13 +712,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				Collection<MessageHeader> headers =
 						db.getInboxMessageHeaders(txn, c);
 				db.commitTransaction(txn);
 				return headers;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -732,12 +732,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsLocalAuthor(txn, a))
+				if (!db.containsLocalAuthor(txn, a))
 					throw new NoSuchLocalAuthorException();
 				LocalAuthor localAuthor = db.getLocalAuthor(txn, a);
 				db.commitTransaction(txn);
 				return localAuthor;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -754,7 +754,7 @@ DatabaseCleaner.Callback {
 				Collection<LocalAuthor> authors = db.getLocalAuthors(txn);
 				db.commitTransaction(txn);
 				return authors;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -773,7 +773,7 @@ DatabaseCleaner.Callback {
 						db.getLocalProperties(txn);
 				db.commitTransaction(txn);
 				return properties;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -788,12 +788,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsTransport(txn, t))
+				if (!db.containsTransport(txn, t))
 					throw new NoSuchTransportException();
 				TransportProperties properties = db.getLocalProperties(txn, t);
 				db.commitTransaction(txn);
 				return properties;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -807,12 +807,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsMessage(txn, m))
+				if (!db.containsMessage(txn, m))
 					throw new NoSuchMessageException();
 				byte[] body = db.getMessageBody(txn, m);
 				db.commitTransaction(txn);
 				return body;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -827,13 +827,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsGroup(txn, g))
+				if (!db.containsGroup(txn, g))
 					throw new NoSuchSubscriptionException();
 				Collection<MessageHeader> headers =
 						db.getMessageHeaders(txn, g);
 				db.commitTransaction(txn);
 				return headers;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -847,12 +847,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsMessage(txn, m))
+				if (!db.containsMessage(txn, m))
 					throw new NoSuchMessageException();
 				boolean read = db.getReadFlag(txn, m);
 				db.commitTransaction(txn);
 				return read;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -871,7 +871,7 @@ DatabaseCleaner.Callback {
 						db.getRemoteProperties(txn, t);
 				db.commitTransaction(txn);
 				return properties;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -888,7 +888,7 @@ DatabaseCleaner.Callback {
 				Collection<TemporarySecret> secrets = db.getSecrets(txn);
 				db.commitTransaction(txn);
 				return secrets;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -905,7 +905,7 @@ DatabaseCleaner.Callback {
 				Settings s = db.getSettings(txn);
 				db.commitTransaction(txn);
 				return s;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -922,7 +922,7 @@ DatabaseCleaner.Callback {
 				Collection<Contact> contacts = db.getSubscribers(txn, g);
 				db.commitTransaction(txn);
 				return contacts;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -941,7 +941,7 @@ DatabaseCleaner.Callback {
 						db.getTransportLatencies(txn);
 				db.commitTransaction(txn);
 				return latencies;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -958,7 +958,7 @@ DatabaseCleaner.Callback {
 				Map<GroupId, Integer> counts = db.getUnreadMessageCounts(txn);
 				db.commitTransaction(txn);
 				return counts;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -972,12 +972,12 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsGroup(txn, g))
+				if (!db.containsGroup(txn, g))
 					throw new NoSuchSubscriptionException();
 				Collection<ContactId> visible = db.getVisibility(txn, g);
 				db.commitTransaction(txn);
 				return visible;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -992,14 +992,14 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
-				if(!db.containsTransport(txn, t))
+				if (!db.containsTransport(txn, t))
 					throw new NoSuchTransportException();
 				long counter = db.incrementStreamCounter(txn, c, t, period);
 				db.commitTransaction(txn);
 				return counter;
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1014,11 +1014,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsTransport(txn, t))
+				if (!db.containsTransport(txn, t))
 					throw new NoSuchTransportException();
 				db.mergeConfig(txn, t, c);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1034,21 +1034,21 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsTransport(txn, t))
+				if (!db.containsTransport(txn, t))
 					throw new NoSuchTransportException();
-				if(!p.equals(db.getLocalProperties(txn, t))) {
+				if (!p.equals(db.getLocalProperties(txn, t))) {
 					db.mergeLocalProperties(txn, t, p);
 					changed = true;
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(changed) eventBus.broadcast(new LocalTransportsUpdatedEvent());
+		if (changed) eventBus.broadcast(new LocalTransportsUpdatedEvent());
 	}
 
 	public void mergeSettings(Settings s) throws DbException {
@@ -1057,19 +1057,19 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!s.equals(db.getSettings(txn))) {
+				if (!s.equals(db.getSettings(txn))) {
 					db.mergeSettings(txn, s);
 					changed = true;
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(changed) eventBus.broadcast(new SettingsUpdatedEvent());
+		if (changed) eventBus.broadcast(new SettingsUpdatedEvent());
 	}
 
 	public void receiveAck(ContactId c, Ack a) throws DbException {
@@ -1078,16 +1078,16 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
-				for(MessageId m : a.getMessageIds()) {
-					if(db.containsVisibleMessage(txn, c, m)) {
+				for (MessageId m : a.getMessageIds()) {
+					if (db.containsVisibleMessage(txn, c, m)) {
 						db.raiseSeenFlag(txn, c, m);
 						acked.add(m);
 					}
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1103,24 +1103,24 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				duplicate = db.containsMessage(txn, m.getId());
 				visible = db.containsVisibleGroup(txn, c, m.getGroup().getId());
-				if(visible) {
-					if(!duplicate) addMessage(txn, m, c);
+				if (visible) {
+					if (!duplicate) addMessage(txn, m, c);
 					db.raiseAckFlag(txn, c, m.getId());
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(visible) {
-			if(!duplicate)
+		if (visible) {
+			if (!duplicate)
 				eventBus.broadcast(new MessageAddedEvent(m.getGroup(), c));
 			eventBus.broadcast(new MessageToAckEvent(c));
 		}
@@ -1132,30 +1132,30 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				int count = db.countOfferedMessages(txn, c);
-				for(MessageId m : o.getMessageIds()) {
-					if(db.containsVisibleMessage(txn, c, m)) {
+				for (MessageId m : o.getMessageIds()) {
+					if (db.containsVisibleMessage(txn, c, m)) {
 						db.raiseSeenFlag(txn, c, m);
 						db.raiseAckFlag(txn, c, m);
 						ack = true;
-					} else if(count < MAX_OFFERED_MESSAGES) {
+					} else if (count < MAX_OFFERED_MESSAGES) {
 						db.addOfferedMessage(txn, c, m);
 						request = true;
 						count++;
 					}
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(ack) eventBus.broadcast(new MessageToAckEvent(c));
-		if(request) eventBus.broadcast(new MessageToRequestEvent(c));
+		if (ack) eventBus.broadcast(new MessageToAckEvent(c));
+		if (request) eventBus.broadcast(new MessageToRequestEvent(c));
 	}
 
 	public void receiveRequest(ContactId c, Request r) throws DbException {
@@ -1164,24 +1164,24 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
-				for(MessageId m : r.getMessageIds()) {
-					if(db.containsVisibleMessage(txn, c, m)) {
+				for (MessageId m : r.getMessageIds()) {
+					if (db.containsVisibleMessage(txn, c, m)) {
 						db.raiseRequestedFlag(txn, c, m);
 						db.resetExpiryTime(txn, c, m);
 						requested = true;
 					}
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(requested) eventBus.broadcast(new MessageRequestedEvent(c));
+		if (requested) eventBus.broadcast(new MessageRequestedEvent(c));
 	}
 
 	public void receiveRetentionAck(ContactId c, RetentionAck a)
@@ -1190,11 +1190,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				db.setRetentionUpdateAcked(txn, c, a.getVersion());
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1210,19 +1210,19 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				long retention = u.getRetentionTime(), version = u.getVersion();
 				updated = db.setRetentionTime(txn, c, retention, version);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(updated) eventBus.broadcast(new RemoteRetentionTimeUpdatedEvent(c));
+		if (updated) eventBus.broadcast(new RemoteRetentionTimeUpdatedEvent(c));
 	}
 
 	public void receiveSubscriptionAck(ContactId c, SubscriptionAck a)
@@ -1231,11 +1231,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				db.setSubscriptionUpdateAcked(txn, c, a.getVersion());
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1251,18 +1251,18 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				updated = db.setGroups(txn, c, u.getGroups(), u.getVersion());
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(updated) eventBus.broadcast(new RemoteSubscriptionsUpdatedEvent(c));
+		if (updated) eventBus.broadcast(new RemoteSubscriptionsUpdatedEvent(c));
 	}
 
 	public void receiveTransportAck(ContactId c, TransportAck a)
@@ -1271,13 +1271,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
-				if(!db.containsTransport(txn, a.getId()))
+				if (!db.containsTransport(txn, a.getId()))
 					throw new NoSuchTransportException();
 				db.setTransportUpdateAcked(txn, c, a.getId(), a.getVersion());
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1293,21 +1293,21 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				TransportId t = u.getId();
 				TransportProperties p = u.getProperties();
 				long version = u.getVersion();
 				updated = db.setRemoteProperties(txn, c, t, p, version);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(updated)
+		if (updated)
 			eventBus.broadcast(new RemoteTransportsUpdatedEvent(c, u.getId()));
 	}
 
@@ -1316,13 +1316,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				GroupId g = db.getInboxGroupId(txn, c);
-				if(g != null) db.removeGroup(txn, g);
+				if (g != null) db.removeGroup(txn, g);
 				db.removeContact(txn, c);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1339,12 +1339,12 @@ DatabaseCleaner.Callback {
 			T txn = db.startTransaction();
 			try {
 				GroupId id = g.getId();
-				if(!db.containsGroup(txn, id))
+				if (!db.containsGroup(txn, id))
 					throw new NoSuchSubscriptionException();
 				affected = db.getVisibility(txn, id);
 				db.removeGroup(txn, id);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1361,23 +1361,23 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsLocalAuthor(txn, a))
+				if (!db.containsLocalAuthor(txn, a))
 					throw new NoSuchLocalAuthorException();
 				affected = db.getContacts(txn, a);
-				for(ContactId c : affected) {
+				for (ContactId c : affected) {
 					GroupId g = db.getInboxGroupId(txn, c);
-					if(g != null) db.removeGroup(txn, g);
+					if (g != null) db.removeGroup(txn, g);
 				}
 				db.removeLocalAuthor(txn, a);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		for(ContactId c : affected)
+		for (ContactId c : affected)
 			eventBus.broadcast(new ContactRemovedEvent(c));
 		eventBus.broadcast(new LocalAuthorRemovedEvent(a));
 	}
@@ -1387,11 +1387,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsTransport(txn, t))
+				if (!db.containsTransport(txn, t))
 					throw new NoSuchTransportException();
 				db.removeTransport(txn, t);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1407,13 +1407,13 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
-				if(!db.containsTransport(txn, t))
+				if (!db.containsTransport(txn, t))
 					throw new NoSuchTransportException();
 				db.setReorderingWindow(txn, c, t, period, centre, bitmap);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1427,11 +1427,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				db.setInboxGroup(txn, c, g);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1445,11 +1445,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsMessage(txn, m))
+				if (!db.containsMessage(txn, m))
 					throw new NoSuchMessageException();
 				db.setReadFlag(txn, m, read);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1464,11 +1464,11 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsContact(txn, c))
+				if (!db.containsContact(txn, c))
 					throw new NoSuchContactException();
 				db.setRemoteProperties(txn, c, p);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
@@ -1484,20 +1484,20 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsGroup(txn, g))
+				if (!db.containsGroup(txn, g))
 					throw new NoSuchSubscriptionException();
 				// Use HashSets for O(1) lookups, O(n) overall running time
 				HashSet<ContactId> now = new HashSet<ContactId>(visible);
 				Collection<ContactId> before = db.getVisibility(txn, g);
 				before = new HashSet<ContactId>(before);
 				// Set the group's visibility for each current contact
-				for(ContactId c : db.getContactIds(txn)) {
+				for (ContactId c : db.getContactIds(txn)) {
 					boolean wasBefore = before.contains(c);
 					boolean isNow = now.contains(c);
-					if(!wasBefore && isNow) {
+					if (!wasBefore && isNow) {
 						db.addVisibility(txn, c, g);
 						affected.add(c);
-					} else if(wasBefore && !isNow) {
+					} else if (wasBefore && !isNow) {
 						db.removeVisibility(txn, c, g);
 						affected.add(c);
 					}
@@ -1505,14 +1505,14 @@ DatabaseCleaner.Callback {
 				// Make the group invisible to future contacts
 				db.setVisibleToAll(txn, g, false);
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(!affected.isEmpty())
+		if (!affected.isEmpty())
 			eventBus.broadcast(new LocalSubscriptionsUpdatedEvent(affected));
 	}
 
@@ -1522,39 +1522,39 @@ DatabaseCleaner.Callback {
 		try {
 			T txn = db.startTransaction();
 			try {
-				if(!db.containsGroup(txn, g))
+				if (!db.containsGroup(txn, g))
 					throw new NoSuchSubscriptionException();
 				// Make the group visible or invisible to future contacts
 				db.setVisibleToAll(txn, g, all);
-				if(all) {
+				if (all) {
 					// Make the group visible to all current contacts
 					Collection<ContactId> before = db.getVisibility(txn, g);
 					before = new HashSet<ContactId>(before);
-					for(ContactId c : db.getContactIds(txn)) {
-						if(!before.contains(c)) {
+					for (ContactId c : db.getContactIds(txn)) {
+						if (!before.contains(c)) {
 							db.addVisibility(txn, c, g);
 							affected.add(c);
 						}
 					}
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(!affected.isEmpty())
+		if (!affected.isEmpty())
 			eventBus.broadcast(new LocalSubscriptionsUpdatedEvent(affected));
 	}
 
 	public void checkFreeSpaceAndClean() throws DbException {
 		long freeSpace = db.getFreeSpace();
-		if(LOG.isLoggable(INFO)) LOG.info(freeSpace + " bytes free space");
-		while(freeSpace < MIN_FREE_SPACE) {
+		if (LOG.isLoggable(INFO)) LOG.info(freeSpace + " bytes free space");
+		while (freeSpace < MIN_FREE_SPACE) {
 			boolean expired = expireMessages(BYTES_PER_SWEEP);
-			if(freeSpace < CRITICAL_FREE_SPACE && !expired) {
+			if (freeSpace < CRITICAL_FREE_SPACE && !expired) {
 				// FIXME: Work out what to do here
 				throw new Error("Disk space is critically low");
 			}
@@ -1575,27 +1575,27 @@ DatabaseCleaner.Callback {
 			T txn = db.startTransaction();
 			try {
 				expired = db.getOldMessages(txn, size);
-				if(!expired.isEmpty()) {
-					for(MessageId m : expired) db.removeMessage(txn, m);
+				if (!expired.isEmpty()) {
+					for (MessageId m : expired) db.removeMessage(txn, m);
 					db.incrementRetentionVersions(txn);
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Expired " + expired.size() + " messages");
 				}
 				db.commitTransaction(txn);
-			} catch(DbException e) {
+			} catch (DbException e) {
 				db.abortTransaction(txn);
 				throw e;
 			}
 		} finally {
 			lock.writeLock().unlock();
 		}
-		if(expired.isEmpty()) return false;
+		if (expired.isEmpty()) return false;
 		eventBus.broadcast(new MessageExpiredEvent());
 		return true;
 	}
 
 	public boolean shouldCheckFreeSpace() {
-		if(db.getTransactionCount() > MAX_TRANSACTIONS_BETWEEN_SPACE_CHECKS) {
+		if (db.getTransactionCount() > MAX_TRANSACTIONS_BETWEEN_SPACE_CHECKS) {
 			db.resetTransactionCount();
 			return true;
 		}
diff --git a/briar-core/src/org/briarproject/db/ExponentialBackoff.java b/briar-core/src/org/briarproject/db/ExponentialBackoff.java
index 5248e8e50c..bbb5bc112c 100644
--- a/briar-core/src/org/briarproject/db/ExponentialBackoff.java
+++ b/briar-core/src/org/briarproject/db/ExponentialBackoff.java
@@ -12,15 +12,15 @@ class ExponentialBackoff {
 	 * be greater than Long.MAX_VALUE, Long.MAX_VALUE is returned.
 	 */
 	static long calculateExpiry(long now, int maxLatency, int txCount) {
-		if(now < 0) throw new IllegalArgumentException();
-		if(maxLatency <= 0) throw new IllegalArgumentException();
-		if(txCount < 0) throw new IllegalArgumentException();
+		if (now < 0) throw new IllegalArgumentException();
+		if (maxLatency <= 0) throw new IllegalArgumentException();
+		if (txCount < 0) throw new IllegalArgumentException();
 		// The maximum round-trip time is twice the maximum latency
 		long roundTrip = maxLatency * 2L;
 		// The interval between transmissions is roundTrip * 2 ^ txCount
-		for(int i = 0; i < txCount; i++) {
+		for (int i = 0; i < txCount; i++) {
 			roundTrip <<= 1;
-			if(roundTrip < 0) return Long.MAX_VALUE;
+			if (roundTrip < 0) return Long.MAX_VALUE;
 		}
 		// The expiry time is the current time plus the interval
 		long expiry = now + roundTrip;
diff --git a/briar-core/src/org/briarproject/db/H2Database.java b/briar-core/src/org/briarproject/db/H2Database.java
index f357593910..4eb28f89e0 100644
--- a/briar-core/src/org/briarproject/db/H2Database.java
+++ b/briar-core/src/org/briarproject/db/H2Database.java
@@ -41,7 +41,7 @@ class H2Database extends JdbcDatabase {
 
 	public boolean open() throws DbException, IOException {
 		boolean reopen = config.databaseExists();
-		if(!reopen) config.getDatabaseDirectory().mkdirs();
+		if (!reopen) config.getDatabaseDirectory().mkdirs();
 		super.open("org.h2.Driver", reopen);
 		return reopen;
 	}
@@ -50,7 +50,7 @@ class H2Database extends JdbcDatabase {
 		// H2 will close the database when the last connection closes
 		try {
 			super.closeAllConnections();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			throw new DbException(e);
 		}
 	}
@@ -64,17 +64,17 @@ class H2Database extends JdbcDatabase {
 			long quota = maxSize - used;
 			long min =  Math.min(free, quota);
 			return min;
-		} catch(IOException e) {
+		} catch (IOException e) {
 			throw new DbException(e);
 		}
 	}
 
 	private long getDiskSpace(File f) {
-		if(f.isDirectory()) {
+		if (f.isDirectory()) {
 			long total = 0;
-			for(File child : f.listFiles()) total += getDiskSpace(child);
+			for (File child : f.listFiles()) total += getDiskSpace(child);
 			return total;
-		} else if(f.isFile()) {
+		} else if (f.isFile()) {
 			return f.length();
 		} else {
 			return 0;
@@ -84,7 +84,7 @@ class H2Database extends JdbcDatabase {
 	@Override
 	protected Connection createConnection() throws SQLException {
 		byte[] key = config.getEncryptionKey().getBytes();
-		if(key == null) throw new IllegalStateException();
+		if (key == null) throw new IllegalStateException();
 		Properties props = new Properties();
 		props.setProperty("user", "user");
 		// Separate the file password from the user password with a space
diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java
index 13248ddca7..61add5a157 100644
--- a/briar-core/src/org/briarproject/db/JdbcDatabase.java
+++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java
@@ -342,14 +342,14 @@ abstract class JdbcDatabase implements Database<Connection> {
 		// Load the JDBC driver
 		try {
 			Class.forName(driverClass);
-		} catch(ClassNotFoundException e) {
+		} catch (ClassNotFoundException e) {
 			throw new DbException(e);
 		}
 		// Open the database and create the tables if necessary
 		Connection txn = startTransaction();
 		try {
-			if(reopen) {
-				if(!checkSchemaVersion(txn)) throw new DbException();
+			if (reopen) {
+				if (!checkSchemaVersion(txn)) throw new DbException();
 			} else {
 				createTables(txn);
 				Settings s = new Settings();
@@ -358,7 +358,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 				mergeSettings(txn, s);
 			}
 			commitTransaction(txn);
-		} catch(DbException e) {
+		} catch (DbException e) {
 			abortTransaction(txn);
 			throw e;
 		}
@@ -368,28 +368,28 @@ abstract class JdbcDatabase implements Database<Connection> {
 		try {
 			Settings s = getSettings(txn);
 			int schemaVersion = Integer.valueOf(s.get("schemaVersion"));
-			if(schemaVersion == SCHEMA_VERSION) return true;
-			if(schemaVersion < MIN_SCHEMA_VERSION) return false;
+			if (schemaVersion == SCHEMA_VERSION) return true;
+			if (schemaVersion < MIN_SCHEMA_VERSION) return false;
 			int minSchemaVersion = Integer.valueOf(s.get("minSchemaVersion"));
 			return SCHEMA_VERSION >= minSchemaVersion;
-		} catch(NumberFormatException e) {
+		} catch (NumberFormatException e) {
 			throw new DbException(e);
 		}
 	}
 
 	private void tryToClose(ResultSet rs) {
 		try {
-			if(rs != null) rs.close();
-		} catch(SQLException e) {
-			if(LOG.isLoggable(WARNING))LOG.log(WARNING, e.toString(), e);
+			if (rs != null) rs.close();
+		} catch (SQLException e) {
+			if (LOG.isLoggable(WARNING))LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	private void tryToClose(Statement s) {
 		try {
-			if(s != null) s.close();
-		} catch(SQLException e) {
-			if(LOG.isLoggable(WARNING))LOG.log(WARNING, e.toString(), e);
+			if (s != null) s.close();
+		} catch (SQLException e) {
+			if (LOG.isLoggable(WARNING))LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
@@ -420,7 +420,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			s.executeUpdate(insertTypeNames(CREATE_ENDPOINTS));
 			s.executeUpdate(insertTypeNames(CREATE_SECRETS));
 			s.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(s);
 			throw new DbException(e);
 		}
@@ -438,16 +438,16 @@ abstract class JdbcDatabase implements Database<Connection> {
 		Connection txn = null;
 		connectionsLock.lock();
 		try {
-			if(closed) throw new DbClosedException();
+			if (closed) throw new DbClosedException();
 			txn = connections.poll();
 		} finally {
 			connectionsLock.unlock();
 		}
 		try {
-			if(txn == null) {
+			if (txn == null) {
 				// Open a new connection
 				txn = createConnection();
-				if(txn == null) throw new DbException();
+				if (txn == null) throw new DbException();
 				txn.setAutoCommit(false);
 				connectionsLock.lock();
 				try {
@@ -456,7 +456,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 					connectionsLock.unlock();
 				}
 			}
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			throw new DbException(e);
 		}
 		transactionCount.incrementAndGet();
@@ -473,13 +473,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			} finally {
 				connectionsLock.unlock();
 			}
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			// Try to close the connection
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			try {
 				txn.close();
-			} catch(SQLException e1) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e1.toString(), e1);
+			} catch (SQLException e1) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e1.toString(), e1);
 			}
 			// Whatever happens, allow the database to close
 			connectionsLock.lock();
@@ -499,7 +499,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			s = txn.createStatement();
 			flushBuffersToDisk(s);
 			s.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(s);
 			throw new DbException(e);
 		}
@@ -525,17 +525,17 @@ abstract class JdbcDatabase implements Database<Connection> {
 		connectionsLock.lock();
 		try {
 			closed = true;
-			for(Connection c : connections) c.close();
+			for (Connection c : connections) c.close();
 			openConnections -= connections.size();
 			connections.clear();
-			while(openConnections > 0) {
+			while (openConnections > 0) {
 				try {
 					connectionsChanged.await();
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.warning("Interrupted while closing connections");
 					interrupted = true;
 				}
-				for(Connection c : connections) c.close();
+				for (Connection c : connections) c.close();
 				openConnections -= connections.size();
 				connections.clear();
 			}
@@ -543,7 +543,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			connectionsLock.unlock();
 		}
 
-		if(interrupted) Thread.currentThread().interrupt();
+		if (interrupted) Thread.currentThread().interrupt();
 	}
 
 	public ContactId addContact(Connection txn, Author remote, AuthorId local)
@@ -561,16 +561,16 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(3, remote.getPublicKey());
 			ps.setBytes(4, local.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			// Get the new (highest) contact ID
 			sql = "SELECT contactId FROM contacts"
 					+ " ORDER BY contactId DESC LIMIT 1";
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			ContactId c = new ContactId(rs.getInt(1));
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			// Create a status row for each message
@@ -578,24 +578,24 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			Collection<byte[]> ids = new ArrayList<byte[]>();
-			while(rs.next()) ids.add(rs.getBytes(1));
+			while (rs.next()) ids.add(rs.getBytes(1));
 			rs.close();
 			ps.close();
-			if(!ids.isEmpty()) {
+			if (!ids.isEmpty()) {
 				sql = "INSERT INTO statuses (messageId, contactId, ack,"
 						+ " seen, requested, expiry, txCount)"
 						+ " VALUES (?, ?, FALSE, FALSE, FALSE, 0, 0)";
 				ps = txn.prepareStatement(sql);
 				ps.setInt(2, c.getInt());
-				for(byte[] id : ids) {
+				for (byte[] id : ids) {
 					ps.setBytes(1, id);
 					ps.addBatch();
 				}
 				int[] batchAffected = ps.executeBatch();
-				if(batchAffected.length != ids.size())
+				if (batchAffected.length != ids.size())
 					throw new DbStateException();
-				for(int i = 0; i < batchAffected.length; i++) {
-					if(batchAffected[i] != 1) throw new DbStateException();
+				for (int i = 0; i < batchAffected.length; i++) {
+					if (batchAffected[i] != 1) throw new DbStateException();
 				}
 				ps.close();
 			}
@@ -604,24 +604,24 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			ids = new ArrayList<byte[]>();
-			while(rs.next()) ids.add(rs.getBytes(1));
+			while (rs.next()) ids.add(rs.getBytes(1));
 			rs.close();
 			ps.close();
-			if(!ids.isEmpty()) {
+			if (!ids.isEmpty()) {
 				sql = "INSERT INTO groupVisibilities"
 						+ " (contactId, groupId, inbox)"
 						+ " VALUES (?, ?, FALSE)";
 				ps = txn.prepareStatement(sql);
 				ps.setInt(1, c.getInt());
-				for(byte[] id : ids) {
+				for (byte[] id : ids) {
 					ps.setBytes(2, id);
 					ps.addBatch();
 				}
 				int[] batchAffected = ps.executeBatch();
-				if(batchAffected.length != ids.size())
+				if (batchAffected.length != ids.size())
 					throw new DbStateException();
-				for(int i = 0; i < batchAffected.length; i++) {
-					if(batchAffected[i] != 1) throw new DbStateException();
+				for (int i = 0; i < batchAffected.length; i++) {
+					if (batchAffected[i] != 1) throw new DbStateException();
 				}
 				ps.close();
 			}
@@ -633,7 +633,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			// Create a group version row
 			sql = "INSERT INTO groupVersions (contactId, localVersion,"
@@ -643,35 +643,35 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			// Create a transport version row for each local transport
 			sql = "SELECT transportId FROM transports";
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			Collection<String> transports = new ArrayList<String>();
-			while(rs.next()) transports.add(rs.getString(1));
+			while (rs.next()) transports.add(rs.getString(1));
 			rs.close();
 			ps.close();
-			if(transports.isEmpty()) return c;
+			if (transports.isEmpty()) return c;
 			sql = "INSERT INTO transportVersions (contactId, transportId,"
 					+ " localVersion, localAcked, expiry, txCount)"
 					+ " VALUES (?, ?, 1, 0, 0, 0)";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
-			for(String t : transports) {
+			for (String t : transports) {
 				ps.setString(2, t);
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != transports.size())
+			if (batchAffected.length != transports.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
 			return c;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -690,9 +690,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setLong(3, ep.getEpoch());
 			ps.setBoolean(4, ep.getAlice());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -705,13 +705,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			String sql = "SELECT COUNT (groupId) FROM groups";
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			int count = rs.getInt(1);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
-			if(count > MAX_SUBSCRIPTIONS) throw new DbStateException();
-			if(count == MAX_SUBSCRIPTIONS) return false;
+			if (count > MAX_SUBSCRIPTIONS) throw new DbStateException();
+			if (count == MAX_SUBSCRIPTIONS) return false;
 			sql = "INSERT INTO groups"
 					+ " (groupId, name, salt, visibleToAll)"
 					+ " VALUES (?, ?, ?, FALSE)";
@@ -720,10 +720,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(2, g.getName());
 			ps.setBytes(3, g.getSalt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			return true;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -744,9 +744,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(4, a.getPrivateKey());
 			ps.setLong(5, a.getTimeCreated());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -763,11 +763,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 					+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, FALSE)";
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, m.getId().getBytes());
-			if(m.getParent() == null) ps.setNull(2, BINARY);
+			if (m.getParent() == null) ps.setNull(2, BINARY);
 			else ps.setBytes(2, m.getParent().getBytes());
 			ps.setBytes(3, m.getGroup().getId().getBytes());
 			Author a = m.getAuthor();
-			if(a == null) {
+			if (a == null) {
 				ps.setNull(4, BINARY);
 				ps.setNull(5, VARCHAR);
 				ps.setNull(6, BINARY);
@@ -785,9 +785,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(12, raw);
 			ps.setBoolean(13, local);
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -805,18 +805,18 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(2, c.getInt());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
-			if(found) return;
+			if (found) return;
 			sql = "INSERT INTO offers (messageId, contactId) VALUES (?, ?)";
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, m.getBytes());
 			ps.setInt(2, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -832,7 +832,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 					+ " secret, outgoing, centre, bitmap)"
 					+ " VALUES (?, ?, ?, ?, ?, ?, ?)";
 			ps = txn.prepareStatement(sql);
-			for(TemporarySecret s : secrets) {
+			for (TemporarySecret s : secrets) {
 				ps.setInt(1, s.getContactId().getInt());
 				ps.setString(2, s.getTransportId().getString());
 				ps.setLong(3, s.getPeriod());
@@ -843,27 +843,27 @@ abstract class JdbcDatabase implements Database<Connection> {
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != secrets.size())
+			if (batchAffected.length != secrets.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
 			// Delete any obsolete secrets
 			sql = "DELETE FROM secrets"
 					+ " WHERE contactId = ? AND transportId = ? AND period < ?";
 			ps = txn.prepareStatement(sql);
-			for(TemporarySecret s : secrets) {
+			for (TemporarySecret s : secrets) {
 				ps.setInt(1, s.getContactId().getInt());
 				ps.setString(2, s.getTransportId().getString());
 				ps.setLong(3, s.getPeriod() - 2);
 				ps.addBatch();
 			}
 			batchAffected = ps.executeBatch();
-			if(batchAffected.length != secrets.size())
+			if (batchAffected.length != secrets.size())
 				throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -882,9 +882,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBoolean(3, ack);
 			ps.setBoolean(4, seen);
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -901,10 +901,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(1, t.getString());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
-			if(found) return false;
+			if (found) return false;
 			// Create a transport row
 			sql = "INSERT INTO transports (transportId, maxLatency)"
 					+ " VALUES (?, ?)";
@@ -912,34 +912,34 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(1, t.getString());
 			ps.setLong(2, maxLatency);
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			// Create a transport version row for each contact
 			sql = "SELECT contactId FROM contacts";
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			Collection<Integer> contacts = new ArrayList<Integer>();
-			while(rs.next()) contacts.add(rs.getInt(1));
+			while (rs.next()) contacts.add(rs.getInt(1));
 			rs.close();
 			ps.close();
-			if(contacts.isEmpty()) return true;
+			if (contacts.isEmpty()) return true;
 			sql = "INSERT INTO transportVersions (contactId, transportId,"
 					+ " localVersion, localAcked, expiry, txCount)"
 					+ " VALUES (?, ?, 1, 0, 0, 0)";
 			ps = txn.prepareStatement(sql);
 			ps.setString(2, t.getString());
-			for(Integer c : contacts) {
+			for (Integer c : contacts) {
 				ps.setInt(1, c);
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != contacts.size())
+			if (batchAffected.length != contacts.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			return true;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -957,7 +957,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			ps.setBytes(2, g.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			// Bump the subscription version
 			sql = "UPDATE groupVersions"
@@ -967,9 +967,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -985,11 +985,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, a.getBytes());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1006,11 +1006,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1027,11 +1027,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, g.getBytes());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1048,11 +1048,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, a.getBytes());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1069,11 +1069,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, m.getBytes());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1090,11 +1090,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(1, t.getString());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1113,11 +1113,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(2, g.getBytes());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1139,11 +1139,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(2, c.getInt());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1160,13 +1160,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbException();
+			if (!rs.next()) throw new DbException();
 			int count = rs.getInt(1);
-			if(rs.next()) throw new DbException();
+			if (rs.next()) throw new DbException();
 			rs.close();
 			ps.close();
 			return count;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1188,9 +1188,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs = ps.executeQuery();
 			List<Group> groups = new ArrayList<Group>();
 			Set<GroupId> ids = new HashSet<GroupId>();
-			while(rs.next()) {
+			while (rs.next()) {
 				GroupId id = new GroupId(rs.getBytes(1));
-				if(!ids.add(id)) throw new DbStateException();
+				if (!ids.add(id)) throw new DbStateException();
 				String name = rs.getString(2);
 				byte[] salt = rs.getBytes(3);
 				groups.add(new Group(id, name, salt));
@@ -1198,7 +1198,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(groups);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1216,11 +1216,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(1, t.getString());
 			rs = ps.executeQuery();
 			TransportConfig c = new TransportConfig();
-			while(rs.next()) c.put(rs.getString(1), rs.getString(2));
+			while (rs.next()) c.put(rs.getString(1), rs.getString(2));
 			rs.close();
 			ps.close();
 			return c;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1237,7 +1237,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			AuthorId authorId = new AuthorId(rs.getBytes(1));
 			String name = rs.getString(2);
 			byte[] publicKey = rs.getBytes(3);
@@ -1246,7 +1246,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.close();
 			Author author = new Author(authorId, name, publicKey);
 			return new Contact(c, author, localAuthorId);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1262,11 +1262,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			List<ContactId> ids = new ArrayList<ContactId>();
-			while(rs.next()) ids.add(new ContactId(rs.getInt(1)));
+			while (rs.next()) ids.add(new ContactId(rs.getInt(1)));
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1284,7 +1284,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			List<Contact> contacts = new ArrayList<Contact>();
-			while(rs.next()) {
+			while (rs.next()) {
 				ContactId contactId = new ContactId(rs.getInt(1));
 				AuthorId authorId = new AuthorId(rs.getBytes(2));
 				String name = rs.getString(3);
@@ -1296,7 +1296,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(contacts);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1314,11 +1314,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, a.getBytes());
 			rs = ps.executeQuery();
 			List<ContactId> ids = new ArrayList<ContactId>();
-			while(rs.next()) ids.add(new ContactId(rs.getInt(1)));
+			while (rs.next()) ids.add(new ContactId(rs.getInt(1)));
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1335,7 +1335,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			List<Endpoint> endpoints = new ArrayList<Endpoint>();
-			while(rs.next()) {
+			while (rs.next()) {
 				ContactId contactId = new ContactId(rs.getInt(1));
 				TransportId transportId = new TransportId(rs.getString(2));
 				long epoch = rs.getLong(3);
@@ -1344,7 +1344,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 						alice));
 			}
 			return Collections.unmodifiableList(endpoints);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1359,13 +1359,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, g.getBytes());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			String name = rs.getString(1);
 			byte[] salt = rs.getBytes(2);
 			rs.close();
 			ps.close();
 			return new Group(g, name, salt);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1385,7 +1385,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			List<Group> groups = new ArrayList<Group>();
-			while(rs.next()) {
+			while (rs.next()) {
 				GroupId id = new GroupId(rs.getBytes(1));
 				String name = rs.getString(2);
 				byte[] salt = rs.getBytes(3);
@@ -1394,7 +1394,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(groups);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1413,12 +1413,12 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
 			GroupId inbox = null;
-			if(rs.next()) inbox = new GroupId(rs.getBytes(1));
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) inbox = new GroupId(rs.getBytes(1));
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return inbox;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1440,7 +1440,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbException();
+			if (!rs.next()) throw new DbException();
 			AuthorId localId = new AuthorId(rs.getBytes(1));
 			String localName = rs.getString(2);
 			byte[] localKey = rs.getBytes(3);
@@ -1449,7 +1449,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			String remoteName = rs.getString(5);
 			byte[] remoteKey = rs.getBytes(6);
 			Author remoteAuthor = new Author(remoteId, remoteName, remoteKey);
-			if(rs.next()) throw new DbException();
+			if (rs.next()) throw new DbException();
 			// Get the message headers
 			sql = "SELECT m.messageId, parentId, m.groupId, contentType,"
 					+ " timestamp, local, read, seen"
@@ -1467,7 +1467,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
 			List<MessageHeader> headers = new ArrayList<MessageHeader>();
-			while(rs.next()) {
+			while (rs.next()) {
 				MessageId id = new MessageId(rs.getBytes(1));
 				byte[] b = rs.getBytes(2);
 				MessageId parent = b == null ? null : new MessageId(b);
@@ -1484,7 +1484,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(headers);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1502,18 +1502,18 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, a.getBytes());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			String name = rs.getString(1);
 			byte[] publicKey = rs.getBytes(2);
 			byte[] privateKey = rs.getBytes(3);
 			long created = rs.getLong(4);
 			LocalAuthor localAuthor = new LocalAuthor(a, name, publicKey,
 					privateKey, created);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return localAuthor;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1530,7 +1530,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			List<LocalAuthor> authors = new ArrayList<LocalAuthor>();
-			while(rs.next()) {
+			while (rs.next()) {
 				AuthorId authorId = new AuthorId(rs.getBytes(1));
 				String name = rs.getString(2);
 				byte[] publicKey = rs.getBytes(3);
@@ -1542,7 +1542,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(authors);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1563,10 +1563,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 					new HashMap<TransportId, TransportProperties>();
 			TransportId lastId = null;
 			TransportProperties p = null;
-			while(rs.next()) {
+			while (rs.next()) {
 				TransportId id = new TransportId(rs.getString(1));
 				String key = rs.getString(2), value = rs.getString(3);
-				if(!id.equals(lastId)) {
+				if (!id.equals(lastId)) {
 					p = new TransportProperties();
 					properties.put(id, p);
 					lastId = id;
@@ -1576,7 +1576,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableMap(properties);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1594,11 +1594,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(1, t.getString());
 			rs = ps.executeQuery();
 			TransportProperties p = new TransportProperties();
-			while(rs.next()) p.put(rs.getString(1), rs.getString(2));
+			while (rs.next()) p.put(rs.getString(1), rs.getString(2));
 			rs.close();
 			ps.close();
 			return p;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1615,16 +1615,16 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, m.getBytes());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			int bodyStart = rs.getInt(1);
 			int bodyLength = rs.getInt(2);
 			// Bytes are indexed from 1 rather than 0
 			byte[] body = rs.getBlob(3).getBytes(bodyStart + 1, bodyLength);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return body;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1649,13 +1649,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, g.getBytes());
 			rs = ps.executeQuery();
 			List<MessageHeader> headers = new ArrayList<MessageHeader>();
-			while(rs.next()) {
+			while (rs.next()) {
 				MessageId id = new MessageId(rs.getBytes(1));
 				byte[] b = rs.getBytes(2);
 				MessageId parent = b == null ? null : new MessageId(b);
 				Author author;
 				b = rs.getBytes(3);
-				if(b == null) {
+				if (b == null) {
 					author = null;
 				} else {
 					AuthorId authorId = new AuthorId(b);
@@ -1670,8 +1670,8 @@ abstract class JdbcDatabase implements Database<Connection> {
 				boolean isSelf = rs.getBoolean(10);
 				boolean isContact = rs.getBoolean(11);
 				Author.Status status;
-				if(author == null) status = ANONYMOUS;
-				else if(isSelf || isContact) status = VERIFIED;
+				if (author == null) status = ANONYMOUS;
+				else if (isSelf || isContact) status = VERIFIED;
 				else status = UNKNOWN;
 				headers.add(new MessageHeader(id, parent, g, author, status,
 						contentType, timestamp, local, read, false));
@@ -1679,7 +1679,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(headers);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1699,11 +1699,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(2, maxMessages);
 			rs = ps.executeQuery();
 			List<MessageId> ids = new ArrayList<MessageId>();
-			while(rs.next()) ids.add(new MessageId(rs.getBytes(1)));
+			while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1738,11 +1738,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(3, maxMessages);
 			rs = ps.executeQuery();
 			List<MessageId> ids = new ArrayList<MessageId>();
-			while(rs.next()) ids.add(new MessageId(rs.getBytes(1)));
+			while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1762,11 +1762,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(2, maxMessages);
 			rs = ps.executeQuery();
 			List<MessageId> ids = new ArrayList<MessageId>();
-			while(rs.next()) ids.add(new MessageId(rs.getBytes(1)));
+			while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1801,16 +1801,16 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs = ps.executeQuery();
 			List<MessageId> ids = new ArrayList<MessageId>();
 			int total = 0;
-			while(rs.next()) {
+			while (rs.next()) {
 				int length = rs.getInt(1);
-				if(total + length > maxLength) break;
+				if (total + length > maxLength) break;
 				ids.add(new MessageId(rs.getBytes(2)));
 				total += length;
 			}
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1828,16 +1828,16 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs = ps.executeQuery();
 			List<MessageId> ids = new ArrayList<MessageId>();
 			int total = 0;
-			while(rs.next()) {
+			while (rs.next()) {
 				int length = rs.getInt(1);
-				if(total + length > capacity) break;
+				if (total + length > capacity) break;
 				ids.add(new MessageId(rs.getBytes(2)));
 				total += length;
 			}
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1857,14 +1857,14 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, m.getBytes());
 			rs = ps.executeQuery();
 			MessageId parent = null;
-			if(rs.next()) {
+			if (rs.next()) {
 				parent = new MessageId(rs.getBytes(1));
-				if(rs.next()) throw new DbStateException();
+				if (rs.next()) throw new DbStateException();
 			}
 			rs.close();
 			ps.close();
 			return parent;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1880,15 +1880,15 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, m.getBytes());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			int length = rs.getInt(1);
 			byte[] raw = rs.getBlob(2).getBytes(1, length);
-			if(raw.length != length) throw new DbStateException();
-			if(rs.next()) throw new DbStateException();
+			if (raw.length != length) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return raw;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1903,13 +1903,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, m.getBytes());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			boolean read = rs.getBoolean(1);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			return read;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1932,10 +1932,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 					new HashMap<ContactId, TransportProperties>();
 			ContactId lastId = null;
 			TransportProperties p = null;
-			while(rs.next()) {
+			while (rs.next()) {
 				ContactId id = new ContactId(rs.getInt(1));
 				String key = rs.getString(2), value = rs.getString(3);
-				if(!id.equals(lastId)) {
+				if (!id.equals(lastId)) {
 					p = new TransportProperties();
 					properties.put(id, p);
 					lastId = id;
@@ -1945,7 +1945,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableMap(properties);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -1980,16 +1980,16 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs = ps.executeQuery();
 			List<MessageId> ids = new ArrayList<MessageId>();
 			int total = 0;
-			while(rs.next()) {
+			while (rs.next()) {
 				int length = rs.getInt(1);
-				if(total + length > maxLength) break;
+				if (total + length > maxLength) break;
 				ids.add(new MessageId(rs.getBytes(2)));
 				total += length;
 			}
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(ids);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2006,13 +2006,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
-			if(!rs.next()) {
+			if (!rs.next()) {
 				rs.close();
 				ps.close();
 				return null;
 			}
 			long version = rs.getLong(1);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			sql = "UPDATE retentionVersions SET remoteAcked = TRUE"
@@ -2020,10 +2020,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			return new RetentionAck(version);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2045,14 +2045,14 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			ps.setLong(2, now);
 			rs = ps.executeQuery();
-			if(!rs.next()) {
+			if (!rs.next()) {
 				rs.close();
 				ps.close();
 				return null;
 			}
 			long version = rs.getLong(1);
 			int txCount = rs.getInt(2);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			sql = "SELECT timestamp FROM messages AS m"
@@ -2060,11 +2060,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			long retention = 0;
-			if(rs.next()) {
+			if (rs.next()) {
 				retention = rs.getLong(1);
 				retention -= retention % RETENTION_GRANULARITY;
 			}
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			sql = "UPDATE retentionVersions"
@@ -2074,10 +2074,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setLong(1, calculateExpiry(now, maxLatency, txCount));
 			ps.setInt(2, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			return new RetentionUpdate(retention, version);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2098,7 +2098,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			List<TemporarySecret> secrets = new ArrayList<TemporarySecret>();
-			while(rs.next()) {
+			while (rs.next()) {
 				ContactId contactId = new ContactId(rs.getInt(1));
 				TransportId transportId = new TransportId(rs.getString(2));
 				long epoch = rs.getLong(3);
@@ -2114,7 +2114,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(secrets);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2129,11 +2129,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			Settings s = new Settings();
-			while(rs.next()) s.put(rs.getString(1), rs.getString(2));
+			while (rs.next()) s.put(rs.getString(1), rs.getString(2));
 			rs.close();
 			ps.close();
 			return s;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2155,7 +2155,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, g.getBytes());
 			rs = ps.executeQuery();
 			List<Contact> contacts = new ArrayList<Contact>();
-			while(rs.next()) {
+			while (rs.next()) {
 				ContactId contactId = new ContactId(rs.getInt(1));
 				AuthorId authorId = new AuthorId(rs.getBytes(2));
 				String name = rs.getString(3);
@@ -2167,7 +2167,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(contacts);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2184,13 +2184,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
-			if(!rs.next()) {
+			if (!rs.next()) {
 				rs.close();
 				ps.close();
 				return null;
 			}
 			long version = rs.getLong(1);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			sql = "UPDATE groupVersions SET remoteAcked = TRUE"
@@ -2198,10 +2198,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			return new SubscriptionAck(version);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2231,9 +2231,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			Set<GroupId> ids = new HashSet<GroupId>();
 			long version = 0;
 			int txCount = 0;
-			while(rs.next()) {
+			while (rs.next()) {
 				GroupId id = new GroupId(rs.getBytes(1));
-				if(!ids.add(id)) throw new DbStateException();
+				if (!ids.add(id)) throw new DbStateException();
 				String name = rs.getString(2);
 				byte[] salt = rs.getBytes(3);
 				groups.add(new Group(id, name, salt));
@@ -2242,7 +2242,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			}
 			rs.close();
 			ps.close();
-			if(groups.isEmpty()) return null;
+			if (groups.isEmpty()) return null;
 			sql = "UPDATE groupVersions"
 					+ " SET expiry = ?, txCount = txCount + 1"
 					+ " WHERE contactId = ?";
@@ -2250,11 +2250,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setLong(1, calculateExpiry(now, maxLatency, txCount));
 			ps.setInt(2, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			groups = Collections.unmodifiableList(groups);
 			return new SubscriptionUpdate(groups, version);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2273,30 +2273,30 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
 			List<TransportAck> acks = new ArrayList<TransportAck>();
-			while(rs.next()) {
+			while (rs.next()) {
 				TransportId id = new TransportId(rs.getString(1));
 				acks.add(new TransportAck(id, rs.getLong(2)));
 			}
 			rs.close();
 			ps.close();
-			if(acks.isEmpty()) return null;
+			if (acks.isEmpty()) return null;
 			sql = "UPDATE contactTransportVersions SET remoteAcked = TRUE"
 					+ " WHERE contactId = ? AND transportId = ?";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
-			for(TransportAck a : acks) {
+			for (TransportAck a : acks) {
 				ps.setString(2, a.getId().getString());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != acks.size())
+			if (batchAffected.length != acks.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
 			return Collections.unmodifiableList(acks);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2313,14 +2313,14 @@ abstract class JdbcDatabase implements Database<Connection> {
 			rs = ps.executeQuery();
 			Map<TransportId, Integer> latencies =
 					new HashMap<TransportId, Integer>();
-			while(rs.next()){
+			while (rs.next()){
 				TransportId id = new TransportId(rs.getString(1));
 				latencies.put(id, rs.getInt(2));
 			}
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableMap(latencies);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2350,12 +2350,12 @@ abstract class JdbcDatabase implements Database<Connection> {
 			TransportId lastId = null;
 			TransportProperties p = null;
 			List<Integer> txCounts = new ArrayList<Integer>();
-			while(rs.next()) {
+			while (rs.next()) {
 				TransportId id = new TransportId(rs.getString(1));
 				String key = rs.getString(2), value = rs.getString(3);
 				long version = rs.getLong(4);
 				int txCount = rs.getInt(5);
-				if(!id.equals(lastId)) {
+				if (!id.equals(lastId)) {
 					p = new TransportProperties();
 					updates.add(new TransportUpdate(id, p, version));
 					txCounts.add(txCount);
@@ -2365,28 +2365,28 @@ abstract class JdbcDatabase implements Database<Connection> {
 			}
 			rs.close();
 			ps.close();
-			if(updates.isEmpty()) return null;
+			if (updates.isEmpty()) return null;
 			sql = "UPDATE transportVersions"
 					+ " SET expiry = ?, txCount = txCount + 1"
 					+ " WHERE contactId = ? AND transportId = ?";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(2, c.getInt());
 			int i = 0;
-			for(TransportUpdate u : updates) {
+			for (TransportUpdate u : updates) {
 				int txCount = txCounts.get(i++);
 				ps.setLong(1, calculateExpiry(now, maxLatency, txCount));
 				ps.setString(3, u.getId().getString());
 				ps.addBatch();
 			}
 			int [] batchAffected = ps.executeBatch();
-			if(batchAffected.length != updates.size())
+			if (batchAffected.length != updates.size())
 				throw new DbStateException();
-			for(i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
 			return Collections.unmodifiableList(updates);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2405,14 +2405,14 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			rs = ps.executeQuery();
 			Map<GroupId, Integer> counts = new HashMap<GroupId, Integer>();
-			while(rs.next()) {
+			while (rs.next()) {
 				GroupId groupId = new GroupId(rs.getBytes(1));
 				counts.put(groupId, rs.getInt(2));
 			}
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableMap(counts);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2430,11 +2430,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, g.getBytes());
 			rs = ps.executeQuery();
 			List<ContactId> visible = new ArrayList<ContactId>();
-			while(rs.next()) visible.add(new ContactId(rs.getInt(1)));
+			while (rs.next()) visible.add(new ContactId(rs.getInt(1)));
 			rs.close();
 			ps.close();
 			return Collections.unmodifiableList(visible);
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2454,13 +2454,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(2, t.getString());
 			ps.setLong(3, period);
 			rs = ps.executeQuery();
-			if(!rs.next()) {
+			if (!rs.next()) {
 				rs.close();
 				ps.close();
 				return -1;
 			}
 			long streamNumber = rs.getLong(1);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			// Increment the stream counter
@@ -2471,10 +2471,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(2, t.getString());
 			ps.setLong(3, period);
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			return streamNumber;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2488,7 +2488,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 					+ " SET localVersion = localVersion + 1, expiry = 0";
 			ps = txn.prepareStatement(sql);
 			ps.executeUpdate();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2502,19 +2502,19 @@ abstract class JdbcDatabase implements Database<Connection> {
 					+ " WHERE messageId = ? AND contactId = ?";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(2, c.getInt());
-			for(MessageId m : acked) {
+			for (MessageId m : acked) {
 				ps.setBytes(1, m.getBytes());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != acked.size())
+			if (batchAffected.length != acked.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] < 0) throw new DbStateException();
-				if(batchAffected[i] > 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] < 0) throw new DbStateException();
+				if (batchAffected[i] > 1) throw new DbStateException();
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2528,19 +2528,19 @@ abstract class JdbcDatabase implements Database<Connection> {
 					+ " WHERE messageId = ? AND contactId = ?";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(2, c.getInt());
-			for(MessageId m : requested) {
+			for (MessageId m : requested) {
 				ps.setBytes(1, m.getBytes());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != requested.size())
+			if (batchAffected.length != requested.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] < 0) throw new DbStateException();
-				if(batchAffected[i] > 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] < 0) throw new DbStateException();
+				if (batchAffected[i] > 1) throw new DbStateException();
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2566,7 +2566,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(1, t.getString());
 			ps.executeUpdate();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2581,16 +2581,16 @@ abstract class JdbcDatabase implements Database<Connection> {
 					+ " WHERE transportId = ? AND key = ?";
 			ps = txn.prepareStatement(sql);
 			ps.setString(2, t.getString());
-			for(Entry<String, String> e : m.entrySet()) {
+			for (Entry<String, String> e : m.entrySet()) {
 				ps.setString(1, e.getValue());
 				ps.setString(3, e.getKey());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != m.size()) throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] < 0) throw new DbStateException();
-				if(batchAffected[i] > 1) throw new DbStateException();
+			if (batchAffected.length != m.size()) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] < 0) throw new DbStateException();
+				if (batchAffected[i] > 1) throw new DbStateException();
 			}
 			// Insert any properties that don't already exist
 			sql = "INSERT INTO " + tableName + " (transportId, key, value)"
@@ -2598,8 +2598,8 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setString(1, t.getString());
 			int updateIndex = 0, inserted = 0;
-			for(Entry<String, String> e : m.entrySet()) {
-				if(batchAffected[updateIndex] == 0) {
+			for (Entry<String, String> e : m.entrySet()) {
+				if (batchAffected[updateIndex] == 0) {
 					ps.setString(2, e.getKey());
 					ps.setString(3, e.getValue());
 					ps.addBatch();
@@ -2608,12 +2608,12 @@ abstract class JdbcDatabase implements Database<Connection> {
 				updateIndex++;
 			}
 			batchAffected = ps.executeBatch();
-			if(batchAffected.length != inserted) throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			if (batchAffected.length != inserted) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2625,23 +2625,23 @@ abstract class JdbcDatabase implements Database<Connection> {
 			// Update any settings that already exist
 			String sql = "UPDATE settings SET value = ? WHERE key = ?";
 			ps = txn.prepareStatement(sql);
-			for(Entry<String, String> e : s.entrySet()) {
+			for (Entry<String, String> e : s.entrySet()) {
 				ps.setString(1, e.getValue());
 				ps.setString(2, e.getKey());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != s.size()) throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] < 0) throw new DbStateException();
-				if(batchAffected[i] > 1) throw new DbStateException();
+			if (batchAffected.length != s.size()) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] < 0) throw new DbStateException();
+				if (batchAffected[i] > 1) throw new DbStateException();
 			}
 			// Insert any settings that don't already exist
 			sql = "INSERT INTO settings (key, value) VALUES (?, ?)";
 			ps = txn.prepareStatement(sql);
 			int updateIndex = 0, inserted = 0;
-			for(Entry<String, String> e : s.entrySet()) {
-				if(batchAffected[updateIndex] == 0) {
+			for (Entry<String, String> e : s.entrySet()) {
+				if (batchAffected[updateIndex] == 0) {
 					ps.setString(1, e.getKey());
 					ps.setString(2, e.getValue());
 					ps.addBatch();
@@ -2650,12 +2650,12 @@ abstract class JdbcDatabase implements Database<Connection> {
 				updateIndex++;
 			}
 			batchAffected = ps.executeBatch();
-			if(batchAffected.length != inserted) throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			if (batchAffected.length != inserted) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2671,9 +2671,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, m.getBytes());
 			ps.setInt(2, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2690,9 +2690,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, m.getBytes());
 			ps.setInt(2, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2710,9 +2710,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, m.getBytes());
 			ps.setInt(2, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
@@ -2727,9 +2727,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2746,7 +2746,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, g.getBytes());
 			rs = ps.executeQuery();
 			Collection<Integer> visible = new ArrayList<Integer>();
-			while(rs.next()) visible.add(rs.getInt(1));
+			while (rs.next()) visible.add(rs.getInt(1));
 			rs.close();
 			ps.close();
 			// Delete the group
@@ -2754,26 +2754,26 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, g.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-			if(visible.isEmpty()) return;
+			if (visible.isEmpty()) return;
 			// Bump the subscription versions for the affected contacts
 			sql = "UPDATE groupVersions"
 					+ " SET localVersion = localVersion + 1, expiry = 0"
 					+ " WHERE contactId = ?";
 			ps = txn.prepareStatement(sql);
-			for(Integer c : visible) {
+			for (Integer c : visible) {
 				ps.setInt(1, c);
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != visible.size())
+			if (batchAffected.length != visible.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -2788,9 +2788,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, a.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2803,9 +2803,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setBytes(1, m.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2821,10 +2821,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			ps.setBytes(2, m.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
 			return affected == 1;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2838,18 +2838,18 @@ abstract class JdbcDatabase implements Database<Connection> {
 					+ " WHERE contactId = ? AND messageId = ?";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
-			for(MessageId m : requested) {
+			for (MessageId m : requested) {
 				ps.setBytes(2, m.getBytes());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != requested.size())
+			if (batchAffected.length != requested.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2863,9 +2863,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setString(1, t.getString());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2881,7 +2881,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			ps.setBytes(2, g.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			// Bump the subscription version
 			sql = "UPDATE groupVersions"
@@ -2890,9 +2890,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2908,9 +2908,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, m.getBytes());
 			ps.setInt(2, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2928,9 +2928,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(4, t.getString());
 			ps.setLong(5, period);
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -2950,13 +2950,13 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(2, c.getInt());
 			ps.setLong(3, version);
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
 			// Return false if the update is obsolete
-			if(affected == 0) return false;
+			if (affected == 0) return false;
 			// Find any messages in groups that are being removed
 			Set<GroupId> newIds = new HashSet<GroupId>();
-			for(Group g : groups) newIds.add(g.getId());
+			for (Group g : groups) newIds.add(g.getId());
 			sql = "SELECT messageId, m.groupId"
 					+ " FROM messages AS m"
 					+ " JOIN contactGroups AS cg"
@@ -2966,28 +2966,28 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			rs = ps.executeQuery();
 			List<MessageId> removed = new ArrayList<MessageId>();
-			while(rs.next()) {
-				if(!newIds.contains(new GroupId(rs.getBytes(2))))
+			while (rs.next()) {
+				if (!newIds.contains(new GroupId(rs.getBytes(2))))
 					removed.add(new MessageId(rs.getBytes(1)));
 			}
 			rs.close();
 			ps.close();
 			// Reset any statuses for messages in groups that are being removed
-			if(!removed.isEmpty()) {
+			if (!removed.isEmpty()) {
 				sql = "UPDATE statuses SET ack = FALSE, seen = FALSE,"
 						+ " requested = FALSE, expiry = 0, txCount = 0"
 						+ " WHERE contactId = ? AND messageId = ?";
 				ps = txn.prepareStatement(sql);
 				ps.setInt(1, c.getInt());
-				for(MessageId m : removed) {
+				for (MessageId m : removed) {
 					ps.setBytes(2, m.getBytes());
 					ps.addBatch();
 				}
 				int[] batchAffected = ps.executeBatch();
-				if(batchAffected.length != removed.size())
+				if (batchAffected.length != removed.size())
 					throw new DbStateException();
-				for(int i = 0; i < batchAffected.length; i++) {
-					if(batchAffected[i] < 0) throw new DbStateException();
+				for (int i = 0; i < batchAffected.length; i++) {
+					if (batchAffected[i] < 0) throw new DbStateException();
 				}
 				ps.close();
 			}
@@ -2997,27 +2997,27 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			ps.executeUpdate();
 			// Store the new subscriptions, if any
-			if(groups.isEmpty()) return true;
+			if (groups.isEmpty()) return true;
 			sql = "INSERT INTO contactGroups"
 					+ " (contactId, groupId, name, salt)"
 					+ " VALUES (?, ?, ?, ?)";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
-			for(Group g : groups) {
+			for (Group g : groups) {
 				ps.setBytes(2, g.getId().getBytes());
 				ps.setString(3, g.getName());
 				ps.setBytes(4, g.getSalt());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != groups.size())
+			if (batchAffected.length != groups.size())
 				throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
 			return true;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -3037,7 +3037,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			ps.executeUpdate();
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
 			// Make the group visible to the contact and set it as the inbox
 			sql = "INSERT INTO groupVisibilities"
@@ -3047,7 +3047,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(1, c.getInt());
 			ps.setBytes(2, g.getId().getBytes());
 			affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
 			// Add the group to the contact's subscriptions
 			sql = "INSERT INTO contactGroups"
@@ -3059,9 +3059,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(3, g.getName());
 			ps.setBytes(4, g.getSalt());
 			affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3076,9 +3076,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBoolean(1, read);
 			ps.setBytes(2, m.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3102,9 +3102,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			int batchSize = 0;
-			for(Entry<TransportId, TransportProperties> e : p.entrySet()) {
+			for (Entry<TransportId, TransportProperties> e : p.entrySet()) {
 				ps.setString(2, e.getKey().getString());
-				for(Entry<String, String> e1 : e.getValue().entrySet()) {
+				for (Entry<String, String> e1 : e.getValue().entrySet()) {
 					ps.setString(3, e1.getKey());
 					ps.setString(4, e1.getValue());
 					ps.addBatch();
@@ -3112,12 +3112,12 @@ abstract class JdbcDatabase implements Database<Connection> {
 				}
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != batchSize) throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			if (batchAffected.length != batchSize) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3137,11 +3137,11 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setString(2, t.getString());
 			rs = ps.executeQuery();
 			boolean found = rs.next();
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			// Mark the update as needing to be acked
-			if(found) {
+			if (found) {
 				// The row exists - update it
 				sql = "UPDATE contactTransportVersions"
 						+ " SET remoteVersion = ?, remoteAcked = FALSE"
@@ -3153,10 +3153,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 				ps.setString(3, t.getString());
 				ps.setLong(4, version);
 				int affected = ps.executeUpdate();
-				if(affected < 0 || affected > 1) throw new DbStateException();
+				if (affected < 0 || affected > 1) throw new DbStateException();
 				ps.close();
 				// Return false if the update is obsolete
-				if(affected == 0) return false;
+				if (affected == 0) return false;
 			} else {
 				// The row doesn't exist - create it
 				sql = "INSERT INTO contactTransportVersions (contactId,"
@@ -3167,7 +3167,7 @@ abstract class JdbcDatabase implements Database<Connection> {
 				ps.setString(2, t.getString());
 				ps.setLong(3, version);
 				int affected = ps.executeUpdate();
-				if(affected != 1) throw new DbStateException();
+				if (affected != 1) throw new DbStateException();
 				ps.close();
 			}
 			// Delete the existing properties, if any
@@ -3179,26 +3179,26 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.executeUpdate();
 			ps.close();
 			// Store the new properties, if any
-			if(p.isEmpty()) return true;
+			if (p.isEmpty()) return true;
 			sql = "INSERT INTO contactTransportProperties"
 					+ " (contactId, transportId, key, value)"
 					+ " VALUES (?, ?, ?, ?)";
 			ps = txn.prepareStatement(sql);
 			ps.setInt(1, c.getInt());
 			ps.setString(2, t.getString());
-			for(Entry<String, String> e : p.entrySet()) {
+			for (Entry<String, String> e : p.entrySet()) {
 				ps.setString(3, e.getKey());
 				ps.setString(4, e.getValue());
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
-			if(batchAffected.length != p.size()) throw new DbStateException();
-			for(int i = 0; i < batchAffected.length; i++) {
-				if(batchAffected[i] != 1) throw new DbStateException();
+			if (batchAffected.length != p.size()) throw new DbStateException();
+			for (int i = 0; i < batchAffected.length; i++) {
+				if (batchAffected[i] != 1) throw new DbStateException();
 			}
 			ps.close();
 			return true;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			tryToClose(rs);
 			throw new DbException(e);
@@ -3218,10 +3218,10 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setInt(3, c.getInt());
 			ps.setLong(4, version);
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
 			return affected == 1;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3240,9 +3240,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setLong(3, version);
 			ps.setLong(4, version);
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3261,9 +3261,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setLong(3, version);
 			ps.setLong(4, version);
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3283,9 +3283,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setLong(4, version);
 			ps.setLong(5, version);
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3300,9 +3300,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBoolean(1, all);
 			ps.setBytes(2, g.getBytes());
 			int affected = ps.executeUpdate();
-			if(affected < 0 || affected > 1) throw new DbStateException();
+			if (affected < 0 || affected > 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(ps);
 			throw new DbException(e);
 		}
@@ -3319,9 +3319,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(1, m.getBytes());
 			ps.setInt(2, c.getInt());
 			rs = ps.executeQuery();
-			if(!rs.next()) throw new DbStateException();
+			if (!rs.next()) throw new DbStateException();
 			int txCount = rs.getInt(1);
-			if(rs.next()) throw new DbStateException();
+			if (rs.next()) throw new DbStateException();
 			rs.close();
 			ps.close();
 			sql = "UPDATE statuses SET expiry = ?, txCount = txCount + 1"
@@ -3332,9 +3332,9 @@ abstract class JdbcDatabase implements Database<Connection> {
 			ps.setBytes(2, m.getBytes());
 			ps.setInt(3, c.getInt());
 			int affected = ps.executeUpdate();
-			if(affected != 1) throw new DbStateException();
+			if (affected != 1) throw new DbStateException();
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			tryToClose(rs);
 			tryToClose(ps);
 			throw new DbException(e);
diff --git a/briar-core/src/org/briarproject/event/EventBusImpl.java b/briar-core/src/org/briarproject/event/EventBusImpl.java
index 9db72310b6..ca007e10ad 100644
--- a/briar-core/src/org/briarproject/event/EventBusImpl.java
+++ b/briar-core/src/org/briarproject/event/EventBusImpl.java
@@ -21,6 +21,6 @@ class EventBusImpl implements EventBus {
 	}
 
 	public void broadcast(Event e) {
-		for(EventListener l : listeners) l.eventOccurred(e);
+		for (EventListener l : listeners) l.eventOccurred(e);
 	}
 }
diff --git a/briar-core/src/org/briarproject/invitation/AliceConnector.java b/briar-core/src/org/briarproject/invitation/AliceConnector.java
index 1821590289..1e4e533b7b 100644
--- a/briar-core/src/org/briarproject/invitation/AliceConnector.java
+++ b/briar-core/src/org/briarproject/invitation/AliceConnector.java
@@ -58,11 +58,11 @@ class AliceConnector extends Connector {
 	public void run() {
 		// Create an incoming or outgoing connection
 		DuplexTransportConnection conn = createInvitationConnection();
-		if(conn == null) return;
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " connected");
+		if (conn == null) return;
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " connected");
 		// Don't proceed with more than one connection
-		if(group.getAndSetConnected()) {
-			if(LOG.isLoggable(INFO)) LOG.info(pluginName + " redundant");
+		if (group.getAndSetConnected()) {
+			if (LOG.isLoggable(INFO)) LOG.info(pluginName + " redundant");
 			tryToClose(conn, false);
 			return;
 		}
@@ -83,19 +83,19 @@ class AliceConnector extends Connector {
 			sendPublicKey(w);
 			byte[] key = receivePublicKey(r);
 			secret = deriveMasterSecret(hash, key, true);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.keyAgreementFailed();
 			tryToClose(conn, true);
 			return;
-		} catch(GeneralSecurityException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (GeneralSecurityException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.keyAgreementFailed();
 			tryToClose(conn, true);
 			return;
 		}
 		// The key agreement succeeded - derive the confirmation codes
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " agreement succeeded");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " agreement succeeded");
 		int[] codes = crypto.deriveConfirmationCodes(secret);
 		int aliceCode = codes[0], bobCode = codes[1];
 		group.keyAgreementSucceeded(aliceCode, bobCode);
@@ -105,22 +105,22 @@ class AliceConnector extends Connector {
 			localMatched = group.waitForLocalConfirmationResult();
 			sendConfirmation(w, localMatched);
 			remoteMatched = receiveConfirmation(r);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.remoteConfirmationFailed();
 			tryToClose(conn, true);
 			return;
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while waiting for confirmation");
 			group.remoteConfirmationFailed();
 			tryToClose(conn, true);
 			Thread.currentThread().interrupt();
 			return;
 		}
-		if(remoteMatched) group.remoteConfirmationSucceeded();
+		if (remoteMatched) group.remoteConfirmationSucceeded();
 		else group.remoteConfirmationFailed();
-		if(!(localMatched && remoteMatched)) {
-			if(LOG.isLoggable(INFO))
+		if (!(localMatched && remoteMatched)) {
+			if (LOG.isLoggable(INFO))
 				LOG.info(pluginName + " confirmation failed");
 			tryToClose(conn, false);
 			return;
@@ -128,7 +128,7 @@ class AliceConnector extends Connector {
 		// The timestamp is taken after exchanging confirmation results
 		long localTimestamp = clock.currentTimeMillis();
 		// Confirmation succeeded - upgrade to a secure connection
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " confirmation succeeded");
 		// Create the readers
 		InputStream streamReader =
@@ -159,14 +159,14 @@ class AliceConnector extends Connector {
 			remoteReuseConnection = receiveConfirmation(r);
 			// Close the outgoing stream and expect EOF on the incoming stream
 			w.close();
-			if(!r.eof()) LOG.warning("Unexpected data at end of connection");
-		} catch(GeneralSecurityException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (!r.eof()) LOG.warning("Unexpected data at end of connection");
+		} catch (GeneralSecurityException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.pseudonymExchangeFailed();
 			tryToClose(conn, true);
 			return;
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.pseudonymExchangeFailed();
 			tryToClose(conn, true);
 			return;
@@ -176,17 +176,17 @@ class AliceConnector extends Connector {
 		// Add the contact and store the transports
 		try {
 			addContact(remoteAuthor, remoteProps, secret, epoch, true);
-		} catch(DbException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (DbException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			tryToClose(conn, true);
 			group.pseudonymExchangeFailed();
 			return;
 		}
 		// Reuse the connection as a transport connection if both peers agree
-		if(reuseConnection && remoteReuseConnection) reuseConnection(conn);
+		if (reuseConnection && remoteReuseConnection) reuseConnection(conn);
 		else tryToClose(conn, false);
 		// Pseudonym exchange succeeded
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " pseudonym exchange succeeded");
 		group.pseudonymExchangeSucceeded(remoteAuthor);
 	}
diff --git a/briar-core/src/org/briarproject/invitation/BobConnector.java b/briar-core/src/org/briarproject/invitation/BobConnector.java
index 014ed752c9..278e3338d7 100644
--- a/briar-core/src/org/briarproject/invitation/BobConnector.java
+++ b/briar-core/src/org/briarproject/invitation/BobConnector.java
@@ -58,8 +58,8 @@ class BobConnector extends Connector {
 	public void run() {
 		// Create an incoming or outgoing connection
 		DuplexTransportConnection conn = createInvitationConnection();
-		if(conn == null) return;
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " connected");
+		if (conn == null) return;
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " connected");
 		// Carry out the key agreement protocol
 		InputStream in;
 		OutputStream out;
@@ -74,8 +74,8 @@ class BobConnector extends Connector {
 			// Alice goes first
 			byte[] hash = receivePublicKeyHash(r);
 			// Don't proceed with more than one connection
-			if(group.getAndSetConnected()) {
-				if(LOG.isLoggable(INFO)) LOG.info(pluginName + " redundant");
+			if (group.getAndSetConnected()) {
+				if (LOG.isLoggable(INFO)) LOG.info(pluginName + " redundant");
 				tryToClose(conn, false);
 				return;
 			}
@@ -83,19 +83,19 @@ class BobConnector extends Connector {
 			byte[] key = receivePublicKey(r);
 			sendPublicKey(w);
 			secret = deriveMasterSecret(hash, key, false);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.keyAgreementFailed();
 			tryToClose(conn, true);
 			return;
-		} catch(GeneralSecurityException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (GeneralSecurityException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.keyAgreementFailed();
 			tryToClose(conn, true);
 			return;
 		}
 		// The key agreement succeeded - derive the confirmation codes
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " agreement succeeded");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " agreement succeeded");
 		int[] codes = crypto.deriveConfirmationCodes(secret);
 		int aliceCode = codes[0], bobCode = codes[1];
 		group.keyAgreementSucceeded(bobCode, aliceCode);
@@ -105,22 +105,22 @@ class BobConnector extends Connector {
 			remoteMatched = receiveConfirmation(r);
 			localMatched = group.waitForLocalConfirmationResult();
 			sendConfirmation(w, localMatched);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.remoteConfirmationFailed();
 			tryToClose(conn, true);
 			return;
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while waiting for confirmation");
 			group.remoteConfirmationFailed();
 			tryToClose(conn, true);
 			Thread.currentThread().interrupt();
 			return;
 		}
-		if(remoteMatched) group.remoteConfirmationSucceeded();
+		if (remoteMatched) group.remoteConfirmationSucceeded();
 		else group.remoteConfirmationFailed();
-		if(!(localMatched && remoteMatched)) {
-			if(LOG.isLoggable(INFO))
+		if (!(localMatched && remoteMatched)) {
+			if (LOG.isLoggable(INFO))
 				LOG.info(pluginName + " confirmation failed");
 			tryToClose(conn, false);
 			return;
@@ -128,7 +128,7 @@ class BobConnector extends Connector {
 		// The timestamp is taken after exchanging confirmation results
 		long localTimestamp = clock.currentTimeMillis();
 		// Confirmation succeeded - upgrade to a secure connection
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " confirmation succeeded");
 		// Create the readers
 		InputStream streamReader =
@@ -159,14 +159,14 @@ class BobConnector extends Connector {
 			sendConfirmation(w, reuseConnection);
 			// Close the outgoing stream and expect EOF on the incoming stream
 			w.close();
-			if(!r.eof()) LOG.warning("Unexpected data at end of connection");
-		} catch(GeneralSecurityException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (!r.eof()) LOG.warning("Unexpected data at end of connection");
+		} catch (GeneralSecurityException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.pseudonymExchangeFailed();
 			tryToClose(conn, true);
 			return;
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			group.pseudonymExchangeFailed();
 			tryToClose(conn, true);
 			return;
@@ -176,17 +176,17 @@ class BobConnector extends Connector {
 		// Add the contact and store the transports
 		try {
 			addContact(remoteAuthor, remoteProps, secret, epoch, false);
-		} catch(DbException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (DbException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			tryToClose(conn, true);
 			group.pseudonymExchangeFailed();
 			return;
 		}
 		// Reuse the connection as a transport connection if both peers agree
-		if(reuseConnection && remoteReuseConnection) reuseConnection(conn);
+		if (reuseConnection && remoteReuseConnection) reuseConnection(conn);
 		else tryToClose(conn, false);
 		// Pseudonym exchange succeeded
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " pseudonym exchange succeeded");
 		group.pseudonymExchangeSucceeded(remoteAuthor);
 	}
diff --git a/briar-core/src/org/briarproject/invitation/Connector.java b/briar-core/src/org/briarproject/invitation/Connector.java
index c80d578ffa..40517c3a42 100644
--- a/briar-core/src/org/briarproject/invitation/Connector.java
+++ b/briar-core/src/org/briarproject/invitation/Connector.java
@@ -118,7 +118,7 @@ abstract class Connector extends Thread {
 	}
 
 	protected DuplexTransportConnection createInvitationConnection() {
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " creating invitation connection");
 		return plugin.createInvitationConnection(random, CONNECTION_TIMEOUT);
 	}
@@ -126,14 +126,14 @@ abstract class Connector extends Thread {
 	protected void sendPublicKeyHash(Writer w) throws IOException {
 		w.writeRaw(messageDigest.digest(keyPair.getPublic().getEncoded()));
 		w.flush();
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " sent hash");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent hash");
 	}
 
 	protected byte[] receivePublicKeyHash(Reader r) throws IOException {
 		int hashLength = messageDigest.getDigestLength();
 		byte[] b = r.readRaw(hashLength);
-		if(b.length < hashLength) throw new FormatException();
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " received hash");
+		if (b.length < hashLength) throw new FormatException();
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " received hash");
 		return b;
 	}
 
@@ -141,27 +141,27 @@ abstract class Connector extends Thread {
 		byte[] key = keyPair.getPublic().getEncoded();
 		w.writeRaw(key);
 		w.flush();
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " sent key");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent key");
 	}
 
 	protected byte[] receivePublicKey(Reader r) throws GeneralSecurityException,
 	IOException {
 		byte[] b = r.readRaw(MAX_PUBLIC_KEY_LENGTH);
 		keyParser.parsePublicKey(b);
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " received key");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " received key");
 		return b;
 	}
 
 	protected byte[] deriveMasterSecret(byte[] hash, byte[] key, boolean alice)
 			throws GeneralSecurityException {
 		// Check that the hash matches the key
-		if(!Arrays.equals(hash, messageDigest.digest(key))) {
-			if(LOG.isLoggable(INFO))
+		if (!Arrays.equals(hash, messageDigest.digest(key))) {
+			if (LOG.isLoggable(INFO))
 				LOG.info(pluginName + " hash does not match key");
 			throw new GeneralSecurityException();
 		}
 		//  Derive the master secret
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " deriving master secret");
 		return crypto.deriveMasterSecret(key, keyPair, alice);
 	}
@@ -170,13 +170,13 @@ abstract class Connector extends Thread {
 			throws IOException {
 		w.writeBoolean(confirmed);
 		w.flush();
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " sent confirmation: " + confirmed);
 	}
 
 	protected boolean receiveConfirmation(Reader r) throws IOException {
 		boolean confirmed = r.readBoolean();
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " received confirmation: " + confirmed);
 		return confirmed;
 	}
@@ -195,7 +195,7 @@ abstract class Connector extends Thread {
 		w.writeRaw(localAuthor.getPublicKey());
 		w.writeRaw(sig);
 		w.flush();
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " sent pseudonym");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent pseudonym");
 	}
 
 	protected Author receivePseudonym(Reader r, byte[] nonce)
@@ -204,14 +204,14 @@ abstract class Connector extends Thread {
 		String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
 		byte[] publicKey = r.readRaw(MAX_PUBLIC_KEY_LENGTH);
 		byte[] sig = r.readRaw(MAX_SIGNATURE_LENGTH);
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " received pseudonym");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " received pseudonym");
 		// Verify the signature
 		Signature signature = crypto.getSignature();
 		KeyParser keyParser = crypto.getSignatureKeyParser();
 		signature.initVerify(keyParser.parsePublicKey(publicKey));
 		signature.update(nonce);
-		if(!signature.verify(sig)) {
-			if(LOG.isLoggable(INFO))
+		if (!signature.verify(sig)) {
+			if (LOG.isLoggable(INFO))
 				LOG.info(pluginName + " invalid signature");
 			throw new GeneralSecurityException();
 		}
@@ -221,25 +221,25 @@ abstract class Connector extends Thread {
 	protected void sendTimestamp(Writer w, long timestamp) throws IOException {
 		w.writeInteger(timestamp);
 		w.flush();
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " sent timestamp");
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent timestamp");
 	}
 
 	protected long receiveTimestamp(Reader r) throws IOException {
 		long timestamp = r.readInteger();
-		if(timestamp < 0) throw new FormatException();
-		if(LOG.isLoggable(INFO)) LOG.info(pluginName + " received timestamp");
+		if (timestamp < 0) throw new FormatException();
+		if (LOG.isLoggable(INFO)) LOG.info(pluginName + " received timestamp");
 		return timestamp;
 	}
 
 	protected void sendTransportProperties(Writer w) throws IOException {
 		w.writeListStart();
-		for(Entry<TransportId, TransportProperties> e : localProps.entrySet()) {
+		for (Entry<TransportId, TransportProperties> e : localProps.entrySet()) {
 			w.writeString(e.getKey().getString());
 			w.writeMap(e.getValue());
 		}
 		w.writeListEnd();
 		w.flush();
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " sent transport properties");
 	}
 
@@ -248,14 +248,14 @@ abstract class Connector extends Thread {
 		Map<TransportId, TransportProperties> remoteProps =
 				new HashMap<TransportId, TransportProperties>();
 		r.readListStart();
-		while(!r.hasListEnd()) {
+		while (!r.hasListEnd()) {
 			String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
-			if(idString.length() == 0) throw new FormatException();
+			if (idString.length() == 0) throw new FormatException();
 			TransportId id = new TransportId(idString);
 			Map<String, String> p = new HashMap<String, String>();
 			r.readMapStart();
-			for(int i = 0; !r.hasMapEnd(); i++) {
-				if(i == MAX_PROPERTIES_PER_TRANSPORT)
+			for (int i = 0; !r.hasMapEnd(); i++) {
+				if (i == MAX_PROPERTIES_PER_TRANSPORT)
 					throw new FormatException();
 				String key = r.readString(MAX_PROPERTY_LENGTH);
 				String value = r.readString(MAX_PROPERTY_LENGTH);
@@ -265,7 +265,7 @@ abstract class Connector extends Thread {
 			remoteProps.put(id, new TransportProperties(p));
 		}
 		r.readListEnd();
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info(pluginName + " received transport properties");
 		return remoteProps;
 	}
@@ -285,20 +285,20 @@ abstract class Connector extends Thread {
 		// Create an endpoint for each transport shared with the contact
 		List<TransportId> ids = new ArrayList<TransportId>();
 		Map<TransportId, Integer> latencies = db.getTransportLatencies();
-		for(TransportId id : localProps.keySet()) {
-			if(latencies.containsKey(id) && remoteProps.containsKey(id))
+		for (TransportId id : localProps.keySet()) {
+			if (latencies.containsKey(id) && remoteProps.containsKey(id))
 				ids.add(id);
 		}
 		// Assign indices to the transports deterministically and derive keys
 		Collections.sort(ids, TransportIdComparator.INSTANCE);
 		int size = ids.size();
-		for(int i = 0; i < size; i++) {
+		for (int i = 0; i < size; i++) {
 			TransportId id = ids.get(i);
 			Endpoint ep = new Endpoint(contactId, id, epoch, alice);
 			int maxLatency = latencies.get(id);
 			try {
 				db.addEndpoint(ep);
-			} catch(NoSuchTransportException e) {
+			} catch (NoSuchTransportException e) {
 				continue;
 			}
 			byte[] initialSecret = crypto.deriveInitialSecret(secret, i);
@@ -312,13 +312,13 @@ abstract class Connector extends Thread {
 			LOG.info("Closing connection");
 			conn.getReader().dispose(exception, true);
 			conn.getWriter().dispose(exception);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	protected void reuseConnection(DuplexTransportConnection conn) {
-		if(contactId == null) throw new IllegalStateException();
+		if (contactId == null) throw new IllegalStateException();
 		TransportId t = plugin.getId();
 		connectionManager.manageOutgoingConnection(contactId, t, conn);
 	}
diff --git a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java
index 7c676e5209..cf523e2eef 100644
--- a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java
+++ b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java
@@ -132,29 +132,29 @@ class ConnectorGroup extends Thread implements InvitationTask {
 		try {
 			localAuthor = db.getLocalAuthor(localAuthorId);
 			localProps = db.getLocalProperties();
-		} catch(DbException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (DbException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			synchLock.lock();
 			try {
 				connectionFailed = true;
 			} finally {
 				synchLock.unlock();
 			}
-			for(InvitationListener l : listeners) l.connectionFailed();
+			for (InvitationListener l : listeners) l.connectionFailed();
 			return;
 		}
 		// Start the connection threads
 		Collection<Connector> connectors = new ArrayList<Connector>();
 		// Alice is the party with the smaller invitation code
-		if(localInvitationCode < remoteInvitationCode) {
-			for(DuplexPlugin plugin : pluginManager.getInvitationPlugins()) {
+		if (localInvitationCode < remoteInvitationCode) {
+			for (DuplexPlugin plugin : pluginManager.getInvitationPlugins()) {
 				Connector c = createAliceConnector(plugin, localAuthor,
 						localProps);
 				connectors.add(c);
 				c.start();
 			}
 		} else {
-			for(DuplexPlugin plugin: pluginManager.getInvitationPlugins()) {
+			for (DuplexPlugin plugin: pluginManager.getInvitationPlugins()) {
 				Connector c = createBobConnector(plugin, localAuthor,
 						localProps);
 				connectors.add(c);
@@ -163,20 +163,20 @@ class ConnectorGroup extends Thread implements InvitationTask {
 		}
 		// Wait for the connection threads to finish
 		try {
-			for(Connector c : connectors) c.join();
-		} catch(InterruptedException e) {
+			for (Connector c : connectors) c.join();
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while waiting for connectors");
 			Thread.currentThread().interrupt();
 		}
 		// If none of the threads connected, inform the listeners
-		if(!connected.get()) {
+		if (!connected.get()) {
 			synchLock.lock();
 			try {
 				connectionFailed = true;
 			} finally {
 				synchLock.unlock();
 			}
-			for(InvitationListener l : listeners) l.connectionFailed();
+			for (InvitationListener l : listeners) l.connectionFailed();
 		}
 	}
 
@@ -226,8 +226,8 @@ class ConnectorGroup extends Thread implements InvitationTask {
 
 	boolean getAndSetConnected() {
 		boolean redundant = connected.getAndSet(true);
-		if(!redundant)
-			for(InvitationListener l : listeners) l.connectionSucceeded();
+		if (!redundant)
+			for (InvitationListener l : listeners) l.connectionSucceeded();
 		return redundant;
 	}
 
@@ -239,12 +239,12 @@ class ConnectorGroup extends Thread implements InvitationTask {
 		} finally {
 			synchLock.unlock();
 		}
-		for(InvitationListener l : listeners)
+		for (InvitationListener l : listeners)
 			l.keyAgreementSucceeded(localCode, remoteCode);
 	}
 
 	void keyAgreementFailed() {
-		for(InvitationListener l : listeners) l.keyAgreementFailed();
+		for (InvitationListener l : listeners) l.keyAgreementFailed();
 	}
 
 	boolean waitForLocalConfirmationResult() throws InterruptedException {
@@ -265,7 +265,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
 		} finally {
 			synchLock.unlock();
 		}
-		for(InvitationListener l : listeners) l.remoteConfirmationSucceeded();
+		for (InvitationListener l : listeners) l.remoteConfirmationSucceeded();
 	}
 
 	void remoteConfirmationFailed() {
@@ -276,7 +276,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
 		} finally {
 			synchLock.unlock();
 		}
-		for(InvitationListener l : listeners) l.remoteConfirmationFailed();
+		for (InvitationListener l : listeners) l.remoteConfirmationFailed();
 	}
 
 	void pseudonymExchangeSucceeded(Author remoteAuthor) {
@@ -287,11 +287,11 @@ class ConnectorGroup extends Thread implements InvitationTask {
 		} finally {
 			synchLock.unlock();
 		}
-		for(InvitationListener l : listeners)
+		for (InvitationListener l : listeners)
 			l.pseudonymExchangeSucceeded(name);
 	}
 
 	void pseudonymExchangeFailed() {
-		for(InvitationListener l : listeners) l.pseudonymExchangeFailed();
+		for (InvitationListener l : listeners) l.pseudonymExchangeFailed();
 	}
 }
diff --git a/briar-core/src/org/briarproject/lifecycle/LifecycleManagerImpl.java b/briar-core/src/org/briarproject/lifecycle/LifecycleManagerImpl.java
index 6c68745f9c..f5a8c215c5 100644
--- a/briar-core/src/org/briarproject/lifecycle/LifecycleManagerImpl.java
+++ b/briar-core/src/org/briarproject/lifecycle/LifecycleManagerImpl.java
@@ -50,19 +50,19 @@ class LifecycleManagerImpl implements LifecycleManager {
 	}
 
 	public void register(Service s) {
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Registering service " + s.getClass().getName());
 		services.add(s);
 	}
 
 	public void registerForShutdown(ExecutorService e) {
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Registering executor " + e.getClass().getName());
 		executors.add(e);
 	}
 
 	public StartResult startServices() {
-		if(!startStopSemaphore.tryAcquire()) {
+		if (!startStopSemaphore.tryAcquire()) {
 			LOG.info("Already starting or stopping");
 			return ALREADY_RUNNING;
 		}
@@ -71,35 +71,35 @@ class LifecycleManagerImpl implements LifecycleManager {
 			long now = clock.currentTimeMillis();
 			boolean reopened = db.open();
 			long duration = clock.currentTimeMillis() - now;
-			if(LOG.isLoggable(INFO)) {
-				if(reopened)
+			if (LOG.isLoggable(INFO)) {
+				if (reopened)
 					LOG.info("Reopening database took " + duration + " ms");
 				else LOG.info("Creating database took " + duration + " ms");
 			}
 			dbLatch.countDown();
-			for(Service s : services) {
+			for (Service s : services) {
 				now = clock.currentTimeMillis();
 				boolean started = s.start();
 				duration = clock.currentTimeMillis() - now;
-				if(!started) {
-					if(LOG.isLoggable(WARNING)) {
+				if (!started) {
+					if (LOG.isLoggable(WARNING)) {
 						String name = s.getClass().getName();
 						LOG.warning(name + " did not start");
 					}
 					return SERVICE_ERROR;
 				}
-				if(LOG.isLoggable(INFO)) {
+				if (LOG.isLoggable(INFO)) {
 					String name = s.getClass().getName();
 					LOG.info("Starting " + name + " took " + duration + " ms");
 				}
 			}
 			startupLatch.countDown();
 			return SUCCESS;
-		} catch(DbException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (DbException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			return DB_ERROR;
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			return DB_ERROR;
 		} finally {
 			startStopSemaphore.release();
@@ -109,31 +109,31 @@ class LifecycleManagerImpl implements LifecycleManager {
 	public void stopServices() {
 		try {
 			startStopSemaphore.acquire();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while waiting to stop services");
 			return;
 		}
 		try {
 			LOG.info("Stopping services");
 			eventBus.broadcast(new ShutdownEvent());
-			for(Service s : services) {
+			for (Service s : services) {
 				boolean stopped = s.stop();
-				if(LOG.isLoggable(INFO)) {
+				if (LOG.isLoggable(INFO)) {
 					String name = s.getClass().getName();
-					if(stopped) LOG.info("Service stopped: " + name);
+					if (stopped) LOG.info("Service stopped: " + name);
 					else LOG.warning("Service failed to stop: " + name);
 				}
 			}
-			for(ExecutorService e : executors) e.shutdownNow();
-			if(LOG.isLoggable(INFO))
+			for (ExecutorService e : executors) e.shutdownNow();
+			if (LOG.isLoggable(INFO))
 				LOG.info(executors.size() + " executors shut down");
 			db.close();
 			LOG.info("Database closed");
 			shutdownLatch.countDown();
-		} catch(DbException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (DbException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		} finally {
 			startStopSemaphore.release();
 		}
diff --git a/briar-core/src/org/briarproject/lifecycle/ShutdownManagerImpl.java b/briar-core/src/org/briarproject/lifecycle/ShutdownManagerImpl.java
index 880db5b5eb..f639dc8883 100644
--- a/briar-core/src/org/briarproject/lifecycle/ShutdownManagerImpl.java
+++ b/briar-core/src/org/briarproject/lifecycle/ShutdownManagerImpl.java
@@ -41,7 +41,7 @@ class ShutdownManagerImpl implements ShutdownManager {
 		synchLock.lock();
 		try {
 			Thread hook = hooks.remove(handle);
-			if(hook == null) return false;
+			if (hook == null) return false;
 			else return Runtime.getRuntime().removeShutdownHook(hook);
 		} finally {
 			synchLock.unlock();
diff --git a/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java b/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java
index 9b8b3f57cc..1458137291 100644
--- a/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java
+++ b/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java
@@ -47,7 +47,7 @@ class AuthorFactoryImpl implements AuthorFactory {
 			w.writeString(name);
 			w.writeRaw(publicKey);
 			w.writeListEnd();
-		} catch(IOException e) {
+		} catch (IOException e) {
 			// Shouldn't happen with ByteArrayOutputStream
 			throw new RuntimeException();
 		}
diff --git a/briar-core/src/org/briarproject/messaging/AuthorReader.java b/briar-core/src/org/briarproject/messaging/AuthorReader.java
index 467a054f96..3223b4ca20 100644
--- a/briar-core/src/org/briarproject/messaging/AuthorReader.java
+++ b/briar-core/src/org/briarproject/messaging/AuthorReader.java
@@ -28,7 +28,7 @@ class AuthorReader implements ObjectReader<Author> {
 		// Read and digest the data
 		r.readListStart();
 		String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
-		if(name.length() == 0) throw new FormatException();
+		if (name.length() == 0) throw new FormatException();
 		byte[] publicKey = r.readRaw(MAX_PUBLIC_KEY_LENGTH);
 		r.readListEnd();
 		// Reset the reader
diff --git a/briar-core/src/org/briarproject/messaging/CountingConsumer.java b/briar-core/src/org/briarproject/messaging/CountingConsumer.java
index a9971a9015..8b01aa06b2 100644
--- a/briar-core/src/org/briarproject/messaging/CountingConsumer.java
+++ b/briar-core/src/org/briarproject/messaging/CountingConsumer.java
@@ -24,11 +24,11 @@ class CountingConsumer implements Consumer {
 
 	public void write(byte b) throws IOException {
 		count++;
-		if(count > limit) throw new FormatException();
+		if (count > limit) throw new FormatException();
 	}
 
 	public void write(byte[] b, int off, int len) throws IOException {
 		count += len;
-		if(count > limit) throw new FormatException();
+		if (count > limit) throw new FormatException();
 	}
 }
diff --git a/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java b/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java
index c64c768182..a2b1ff99f8 100644
--- a/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java
+++ b/briar-core/src/org/briarproject/messaging/DuplexOutgoingSession.java
@@ -114,13 +114,13 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 			nextRetxQuery = now + RETX_QUERY_INTERVAL;
 			// Write packets until interrupted
 			try {
-				while(!interrupted) {
+				while (!interrupted) {
 					// Work out how long we should wait for a packet
 					now = clock.currentTimeMillis();
 					long wait = Math.min(nextKeepalive, nextRetxQuery) - now;
-					if(wait < 0) wait = 0;
+					if (wait < 0) wait = 0;
 					// Flush any unflushed data if we're going to wait
-					if(wait > 0 && dataToFlush && writerTasks.isEmpty()) {
+					if (wait > 0 && dataToFlush && writerTasks.isEmpty()) {
 						packetWriter.flush();
 						dataToFlush = false;
 						nextKeepalive = now + maxIdleTime;
@@ -128,9 +128,9 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 					// Wait for a packet
 					ThrowingRunnable<IOException> task = writerTasks.poll(wait,
 							MILLISECONDS);
-					if(task == null) {
+					if (task == null) {
 						now = clock.currentTimeMillis();
-						if(now >= nextRetxQuery) {
+						if (now >= nextRetxQuery) {
 							// Check for retransmittable packets
 							dbExecutor.execute(new GenerateTransportUpdates());
 							dbExecutor.execute(new GenerateSubscriptionUpdate());
@@ -139,21 +139,21 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 							dbExecutor.execute(new GenerateOffer());
 							nextRetxQuery = now + RETX_QUERY_INTERVAL;
 						}
-						if(now >= nextKeepalive) {
+						if (now >= nextKeepalive) {
 							// Flush the stream to keep it alive
 							packetWriter.flush();
 							dataToFlush = false;
 							nextKeepalive = now + maxIdleTime;
 						}
-					} else if(task == CLOSE) {
+					} else if (task == CLOSE) {
 						break;
 					} else {
 						task.run();
 						dataToFlush = true;
 					}
 				}
-				if(dataToFlush) packetWriter.flush();
-			} catch(InterruptedException e) {
+				if (dataToFlush) packetWriter.flush();
+			} catch (InterruptedException e) {
 				LOG.info("Interrupted while waiting for a packet to write");
 				Thread.currentThread().interrupt();
 			}
@@ -168,53 +168,53 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof ContactRemovedEvent) {
+		if (e instanceof ContactRemovedEvent) {
 			ContactRemovedEvent c = (ContactRemovedEvent) e;
-			if(c.getContactId().equals(contactId)) interrupt();
-		} else if(e instanceof MessageAddedEvent) {
+			if (c.getContactId().equals(contactId)) interrupt();
+		} else if (e instanceof MessageAddedEvent) {
 			dbExecutor.execute(new GenerateOffer());
-		} else if(e instanceof MessageExpiredEvent) {
+		} else if (e instanceof MessageExpiredEvent) {
 			dbExecutor.execute(new GenerateRetentionUpdate());
-		} else if(e instanceof LocalSubscriptionsUpdatedEvent) {
+		} else if (e instanceof LocalSubscriptionsUpdatedEvent) {
 			LocalSubscriptionsUpdatedEvent l =
 					(LocalSubscriptionsUpdatedEvent) e;
-			if(l.getAffectedContacts().contains(contactId)) {
+			if (l.getAffectedContacts().contains(contactId)) {
 				dbExecutor.execute(new GenerateSubscriptionUpdate());
 				dbExecutor.execute(new GenerateOffer());
 			}
-		} else if(e instanceof LocalTransportsUpdatedEvent) {
+		} else if (e instanceof LocalTransportsUpdatedEvent) {
 			dbExecutor.execute(new GenerateTransportUpdates());
-		} else if(e instanceof MessageRequestedEvent) {
-			if(((MessageRequestedEvent) e).getContactId().equals(contactId))
+		} else if (e instanceof MessageRequestedEvent) {
+			if (((MessageRequestedEvent) e).getContactId().equals(contactId))
 				dbExecutor.execute(new GenerateBatch());
-		} else if(e instanceof MessageToAckEvent) {
-			if(((MessageToAckEvent) e).getContactId().equals(contactId))
+		} else if (e instanceof MessageToAckEvent) {
+			if (((MessageToAckEvent) e).getContactId().equals(contactId))
 				dbExecutor.execute(new GenerateAck());
-		} else if(e instanceof MessageToRequestEvent) {
-			if(((MessageToRequestEvent) e).getContactId().equals(contactId))
+		} else if (e instanceof MessageToRequestEvent) {
+			if (((MessageToRequestEvent) e).getContactId().equals(contactId))
 				dbExecutor.execute(new GenerateRequest());
-		} else if(e instanceof RemoteRetentionTimeUpdatedEvent) {
+		} else if (e instanceof RemoteRetentionTimeUpdatedEvent) {
 			RemoteRetentionTimeUpdatedEvent r =
 					(RemoteRetentionTimeUpdatedEvent) e;
-			if(r.getContactId().equals(contactId))
+			if (r.getContactId().equals(contactId))
 				dbExecutor.execute(new GenerateRetentionAck());
-		} else if(e instanceof RemoteSubscriptionsUpdatedEvent) {
+		} else if (e instanceof RemoteSubscriptionsUpdatedEvent) {
 			RemoteSubscriptionsUpdatedEvent r =
 					(RemoteSubscriptionsUpdatedEvent) e;
-			if(r.getContactId().equals(contactId)) {
+			if (r.getContactId().equals(contactId)) {
 				dbExecutor.execute(new GenerateSubscriptionAck());
 				dbExecutor.execute(new GenerateOffer());
 			}
-		} else if(e instanceof RemoteTransportsUpdatedEvent) {
+		} else if (e instanceof RemoteTransportsUpdatedEvent) {
 			RemoteTransportsUpdatedEvent r =
 					(RemoteTransportsUpdatedEvent) e;
-			if(r.getContactId().equals(contactId))
+			if (r.getContactId().equals(contactId))
 				dbExecutor.execute(new GenerateTransportAcks());
-		} else if(e instanceof ShutdownEvent) {
+		} else if (e instanceof ShutdownEvent) {
 			interrupt();
-		} else if(e instanceof TransportRemovedEvent) {
+		} else if (e instanceof TransportRemovedEvent) {
 			TransportRemovedEvent t = (TransportRemovedEvent) e;
-			if(t.getTransportId().equals(transportId)) interrupt();
+			if (t.getTransportId().equals(transportId)) interrupt();
 		}
 	}
 
@@ -222,15 +222,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateAck implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			int maxMessages = packetWriter.getMaxMessagesForAck(Long.MAX_VALUE);
 			try {
 				Ack a = db.generateAck(contactId, maxMessages);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated ack: " + (a != null));
-				if(a != null) writerTasks.add(new WriteAck(a));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (a != null) writerTasks.add(new WriteAck(a));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -246,7 +246,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeAck(ack);
 			LOG.info("Sent ack");
 			dbExecutor.execute(new GenerateAck());
@@ -257,15 +257,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateBatch implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				Collection<byte[]> b = db.generateRequestedBatch(contactId,
 						MAX_PAYLOAD_LENGTH, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated batch: " + (b != null));
-				if(b != null) writerTasks.add(new WriteBatch(b));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (b != null) writerTasks.add(new WriteBatch(b));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -281,8 +281,8 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
-			for(byte[] raw : batch) packetWriter.writeMessage(raw);
+			if (interrupted) return;
+			for (byte[] raw : batch) packetWriter.writeMessage(raw);
 			LOG.info("Sent batch");
 			dbExecutor.execute(new GenerateBatch());
 		}
@@ -292,16 +292,16 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateOffer implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			int maxMessages = packetWriter.getMaxMessagesForOffer(
 					Long.MAX_VALUE);
 			try {
 				Offer o = db.generateOffer(contactId, maxMessages, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated offer: " + (o != null));
-				if(o != null) writerTasks.add(new WriteOffer(o));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (o != null) writerTasks.add(new WriteOffer(o));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -317,7 +317,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeOffer(offer);
 			LOG.info("Sent offer");
 			dbExecutor.execute(new GenerateOffer());
@@ -328,16 +328,16 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateRequest implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			int maxMessages = packetWriter.getMaxMessagesForRequest(
 					Long.MAX_VALUE);
 			try {
 				Request r = db.generateRequest(contactId, maxMessages);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated request: " + (r != null));
-				if(r != null) writerTasks.add(new WriteRequest(r));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (r != null) writerTasks.add(new WriteRequest(r));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -353,7 +353,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeRequest(request);
 			LOG.info("Sent request");
 			dbExecutor.execute(new GenerateRequest());
@@ -364,14 +364,14 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateRetentionAck implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				RetentionAck a = db.generateRetentionAck(contactId);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated retention ack: " + (a != null));
-				if(a != null) writerTasks.add(new WriteRetentionAck(a));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (a != null) writerTasks.add(new WriteRetentionAck(a));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -388,7 +388,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeRetentionAck(ack);
 			LOG.info("Sent retention ack");
 			dbExecutor.execute(new GenerateRetentionAck());
@@ -399,15 +399,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateRetentionUpdate implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				RetentionUpdate u =
 						db.generateRetentionUpdate(contactId, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated retention update: " + (u != null));
-				if(u != null) writerTasks.add(new WriteRetentionUpdate(u));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (u != null) writerTasks.add(new WriteRetentionUpdate(u));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -424,7 +424,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeRetentionUpdate(update);
 			LOG.info("Sent retention update");
 			dbExecutor.execute(new GenerateRetentionUpdate());
@@ -435,14 +435,14 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateSubscriptionAck implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				SubscriptionAck a = db.generateSubscriptionAck(contactId);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated subscription ack: " + (a != null));
-				if(a != null) writerTasks.add(new WriteSubscriptionAck(a));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (a != null) writerTasks.add(new WriteSubscriptionAck(a));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -459,7 +459,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeSubscriptionAck(ack);
 			LOG.info("Sent subscription ack");
 			dbExecutor.execute(new GenerateSubscriptionAck());
@@ -470,15 +470,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateSubscriptionUpdate implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				SubscriptionUpdate u =
 						db.generateSubscriptionUpdate(contactId, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated subscription update: " + (u != null));
-				if(u != null) writerTasks.add(new WriteSubscriptionUpdate(u));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (u != null) writerTasks.add(new WriteSubscriptionUpdate(u));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -495,7 +495,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeSubscriptionUpdate(update);
 			LOG.info("Sent subscription update");
 			dbExecutor.execute(new GenerateSubscriptionUpdate());
@@ -506,15 +506,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateTransportAcks implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				Collection<TransportAck> acks =
 						db.generateTransportAcks(contactId);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated transport acks: " + (acks != null));
-				if(acks != null) writerTasks.add(new WriteTransportAcks(acks));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (acks != null) writerTasks.add(new WriteTransportAcks(acks));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -530,8 +530,8 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
-			for(TransportAck a : acks) packetWriter.writeTransportAck(a);
+			if (interrupted) return;
+			for (TransportAck a : acks) packetWriter.writeTransportAck(a);
 			LOG.info("Sent transport acks");
 			dbExecutor.execute(new GenerateTransportAcks());
 		}
@@ -541,15 +541,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateTransportUpdates implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				Collection<TransportUpdate> t =
 						db.generateTransportUpdates(contactId, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated transport updates: " + (t != null));
-				if(t != null) writerTasks.add(new WriteTransportUpdates(t));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (t != null) writerTasks.add(new WriteTransportUpdates(t));
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -566,8 +566,8 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
-			for(TransportUpdate u : updates)
+			if (interrupted) return;
+			for (TransportUpdate u : updates)
 				packetWriter.writeTransportUpdate(u);
 			LOG.info("Sent transport updates");
 			dbExecutor.execute(new GenerateTransportUpdates());
diff --git a/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java b/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java
index f0e335bb8f..37bee81a29 100644
--- a/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java
+++ b/briar-core/src/org/briarproject/messaging/GroupFactoryImpl.java
@@ -40,7 +40,7 @@ class GroupFactoryImpl implements GroupFactory {
 			w.writeString(name);
 			w.writeRaw(salt);
 			w.writeListEnd();
-		} catch(IOException e) {
+		} catch (IOException e) {
 			// Shouldn't happen with ByteArrayOutputStream
 			throw new RuntimeException();
 		}
diff --git a/briar-core/src/org/briarproject/messaging/GroupReader.java b/briar-core/src/org/briarproject/messaging/GroupReader.java
index 84ccaf4d92..6e6f5d3c83 100644
--- a/briar-core/src/org/briarproject/messaging/GroupReader.java
+++ b/briar-core/src/org/briarproject/messaging/GroupReader.java
@@ -27,9 +27,9 @@ class GroupReader implements ObjectReader<Group> {
 		r.addConsumer(digesting);
 		r.readListStart();
 		String name = r.readString(MAX_GROUP_NAME_LENGTH);
-		if(name.length() == 0) throw new FormatException();
+		if (name.length() == 0) throw new FormatException();
 		byte[] salt = r.readRaw(GROUP_SALT_LENGTH);
-		if(salt.length != GROUP_SALT_LENGTH) throw new FormatException();
+		if (salt.length != GROUP_SALT_LENGTH) throw new FormatException();
 		r.readListEnd();
 		r.removeConsumer(digesting);
 		// Build and return the group
diff --git a/briar-core/src/org/briarproject/messaging/IncomingSession.java b/briar-core/src/org/briarproject/messaging/IncomingSession.java
index 1bd8acd66c..a3c8d1cde2 100644
--- a/briar-core/src/org/briarproject/messaging/IncomingSession.java
+++ b/briar-core/src/org/briarproject/messaging/IncomingSession.java
@@ -70,35 +70,35 @@ class IncomingSession implements MessagingSession, EventListener {
 		eventBus.addListener(this);
 		try {
 			// Read packets until interrupted or EOF
-			while(!interrupted && !packetReader.eof()) {
-				if(packetReader.hasAck()) {
+			while (!interrupted && !packetReader.eof()) {
+				if (packetReader.hasAck()) {
 					Ack a = packetReader.readAck();
 					dbExecutor.execute(new ReceiveAck(a));
-				} else if(packetReader.hasMessage()) {
+				} else if (packetReader.hasMessage()) {
 					UnverifiedMessage m = packetReader.readMessage();
 					cryptoExecutor.execute(new VerifyMessage(m));
-				} else if(packetReader.hasOffer()) {
+				} else if (packetReader.hasOffer()) {
 					Offer o = packetReader.readOffer();
 					dbExecutor.execute(new ReceiveOffer(o));
-				} else if(packetReader.hasRequest()) {
+				} else if (packetReader.hasRequest()) {
 					Request r = packetReader.readRequest();
 					dbExecutor.execute(new ReceiveRequest(r));
-				} else if(packetReader.hasRetentionAck()) {
+				} else if (packetReader.hasRetentionAck()) {
 					RetentionAck a = packetReader.readRetentionAck();
 					dbExecutor.execute(new ReceiveRetentionAck(a));
-				} else if(packetReader.hasRetentionUpdate()) {
+				} else if (packetReader.hasRetentionUpdate()) {
 					RetentionUpdate u = packetReader.readRetentionUpdate();
 					dbExecutor.execute(new ReceiveRetentionUpdate(u));
-				} else if(packetReader.hasSubscriptionAck()) {
+				} else if (packetReader.hasSubscriptionAck()) {
 					SubscriptionAck a = packetReader.readSubscriptionAck();
 					dbExecutor.execute(new ReceiveSubscriptionAck(a));
-				} else if(packetReader.hasSubscriptionUpdate()) {
+				} else if (packetReader.hasSubscriptionUpdate()) {
 					SubscriptionUpdate u = packetReader.readSubscriptionUpdate();
 					dbExecutor.execute(new ReceiveSubscriptionUpdate(u));
-				} else if(packetReader.hasTransportAck()) {
+				} else if (packetReader.hasTransportAck()) {
 					TransportAck a = packetReader.readTransportAck();
 					dbExecutor.execute(new ReceiveTransportAck(a));
-				} else if(packetReader.hasTransportUpdate()) {
+				} else if (packetReader.hasTransportUpdate()) {
 					TransportUpdate u = packetReader.readTransportUpdate();
 					dbExecutor.execute(new ReceiveTransportUpdate(u));
 				} else {
@@ -116,14 +116,14 @@ class IncomingSession implements MessagingSession, EventListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof ContactRemovedEvent) {
+		if (e instanceof ContactRemovedEvent) {
 			ContactRemovedEvent c = (ContactRemovedEvent) e;
-			if(c.getContactId().equals(contactId)) interrupt();
-		} else if(e instanceof ShutdownEvent) {
+			if (c.getContactId().equals(contactId)) interrupt();
+		} else if (e instanceof ShutdownEvent) {
 			interrupt();
-		} else if(e instanceof TransportRemovedEvent) {
+		} else if (e instanceof TransportRemovedEvent) {
 			TransportRemovedEvent t = (TransportRemovedEvent) e;
-			if(t.getTransportId().equals(transportId)) interrupt();
+			if (t.getTransportId().equals(transportId)) interrupt();
 		}
 	}
 
@@ -138,8 +138,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveAck(contactId, ack);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -157,8 +157,8 @@ class IncomingSession implements MessagingSession, EventListener {
 			try {
 				Message m = messageVerifier.verifyMessage(message);
 				dbExecutor.execute(new ReceiveMessage(m));
-			} catch(GeneralSecurityException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (GeneralSecurityException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -175,8 +175,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveMessage(contactId, message);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -193,8 +193,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveOffer(contactId, offer);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -211,8 +211,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveRequest(contactId, request);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -229,8 +229,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveRetentionAck(contactId, ack);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -247,8 +247,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveRetentionUpdate(contactId, update);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -265,8 +265,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveSubscriptionAck(contactId, ack);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -283,8 +283,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveSubscriptionUpdate(contactId, update);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -301,8 +301,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveTransportAck(contactId, ack);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -319,8 +319,8 @@ class IncomingSession implements MessagingSession, EventListener {
 		public void run() {
 			try {
 				db.receiveTransportUpdate(contactId, update);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
diff --git a/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java b/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java
index ec5e8f9b37..d584a9daf0 100644
--- a/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java
+++ b/briar-core/src/org/briarproject/messaging/MessageFactoryImpl.java
@@ -61,11 +61,11 @@ class MessageFactoryImpl implements MessageFactory {
 			PrivateKey privateKey, String contentType, long timestamp,
 			byte[] body) throws IOException, GeneralSecurityException {
 		// Validate the arguments
-		if((author == null) != (privateKey == null))
+		if ((author == null) != (privateKey == null))
 			throw new IllegalArgumentException();
-		if(StringUtils.toUtf8(contentType).length > MAX_CONTENT_TYPE_LENGTH)
+		if (StringUtils.toUtf8(contentType).length > MAX_CONTENT_TYPE_LENGTH)
 			throw new IllegalArgumentException();
-		if(body.length > MAX_BODY_LENGTH)
+		if (body.length > MAX_BODY_LENGTH)
 			throw new IllegalArgumentException();
 		// Serialise the message to a buffer
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -76,17 +76,17 @@ class MessageFactoryImpl implements MessageFactory {
 		Consumer digestingConsumer = new DigestingConsumer(messageDigest);
 		w.addConsumer(digestingConsumer);
 		Consumer signingConsumer = null;
-		if(privateKey != null) {
+		if (privateKey != null) {
 			signature.initSign(privateKey);
 			signingConsumer = new SigningConsumer(signature);
 			w.addConsumer(signingConsumer);
 		}
 		// Write the message
 		w.writeListStart();
-		if(parent == null) w.writeNull();
+		if (parent == null) w.writeNull();
 		else w.writeRaw(parent.getBytes());
 		writeGroup(w, group);
-		if(author == null) w.writeNull();
+		if (author == null) w.writeNull();
 		else writeAuthor(w, author);
 		w.writeString(contentType);
 		w.writeInteger(timestamp);
@@ -96,12 +96,12 @@ class MessageFactoryImpl implements MessageFactory {
 		w.writeRaw(body);
 		int bodyStart = (int) counting.getCount() - body.length;
 		// Sign the message with the author's private key, if there is one
-		if(privateKey == null) {
+		if (privateKey == null) {
 			w.writeNull();
 		} else {
 			w.removeConsumer(signingConsumer);
 			byte[] sig = signature.sign();
-			if(sig.length > MAX_SIGNATURE_LENGTH)
+			if (sig.length > MAX_SIGNATURE_LENGTH)
 				throw new IllegalArgumentException();
 			w.writeRaw(sig);
 		}
diff --git a/briar-core/src/org/briarproject/messaging/MessageImpl.java b/briar-core/src/org/briarproject/messaging/MessageImpl.java
index 3ac77ef5bf..32a2caeaf2 100644
--- a/briar-core/src/org/briarproject/messaging/MessageImpl.java
+++ b/briar-core/src/org/briarproject/messaging/MessageImpl.java
@@ -21,9 +21,9 @@ class MessageImpl implements Message {
 	public MessageImpl(MessageId id, MessageId parent, Group group,
 			Author author, String contentType, long timestamp,
 			byte[] raw, int bodyStart, int bodyLength) {
-		if(bodyStart + bodyLength > raw.length)
+		if (bodyStart + bodyLength > raw.length)
 			throw new IllegalArgumentException();
-		if(bodyLength > MAX_BODY_LENGTH)
+		if (bodyLength > MAX_BODY_LENGTH)
 			throw new IllegalArgumentException();
 		this.id = id;
 		this.parent = parent;
diff --git a/briar-core/src/org/briarproject/messaging/MessageReader.java b/briar-core/src/org/briarproject/messaging/MessageReader.java
index 66fa6999da..a415ce0c4c 100644
--- a/briar-core/src/org/briarproject/messaging/MessageReader.java
+++ b/briar-core/src/org/briarproject/messaging/MessageReader.java
@@ -37,27 +37,27 @@ class MessageReader implements ObjectReader<UnverifiedMessage> {
 		r.readListStart();
 		// Read the parent's message ID, if there is one
 		MessageId parent = null;
-		if(r.hasNull()) {
+		if (r.hasNull()) {
 			r.readNull();
 		} else {
 			byte[] b = r.readRaw(UniqueId.LENGTH);
-			if(b.length < UniqueId.LENGTH) throw new FormatException();
+			if (b.length < UniqueId.LENGTH) throw new FormatException();
 			parent = new MessageId(b);
 		}
 		// Read the group
 		Group group = groupReader.readObject(r);
 		// Read the author, if there is one
 		Author author = null;
-		if(r.hasNull()) r.readNull();
+		if (r.hasNull()) r.readNull();
 		else author = authorReader.readObject(r);
 		// Read the content type
 		String contentType = r.readString(MAX_CONTENT_TYPE_LENGTH);
 		// Read the timestamp
 		long timestamp = r.readInteger();
-		if(timestamp < 0) throw new FormatException();
+		if (timestamp < 0) throw new FormatException();
 		// Read the salt
 		byte[] salt = r.readRaw(MESSAGE_SALT_LENGTH);
-		if(salt.length < MESSAGE_SALT_LENGTH) throw new FormatException();
+		if (salt.length < MESSAGE_SALT_LENGTH) throw new FormatException();
 		// Read the message body
 		byte[] body = r.readRaw(MAX_BODY_LENGTH);
 		// Record the offset of the body within the message
@@ -66,7 +66,7 @@ class MessageReader implements ObjectReader<UnverifiedMessage> {
 		int signedLength = (int) counting.getCount();
 		// Read the author's signature, if there is one
 		byte[] signature = null;
-		if(author == null) r.readNull();
+		if (author == null) r.readNull();
 		else signature = r.readRaw(MAX_SIGNATURE_LENGTH);
 		// Read the end of the message
 		r.readListEnd();
diff --git a/briar-core/src/org/briarproject/messaging/MessageVerifierImpl.java b/briar-core/src/org/briarproject/messaging/MessageVerifierImpl.java
index 636be555f4..4daa906662 100644
--- a/briar-core/src/org/briarproject/messaging/MessageVerifierImpl.java
+++ b/briar-core/src/org/briarproject/messaging/MessageVerifierImpl.java
@@ -42,7 +42,7 @@ class MessageVerifierImpl implements MessageVerifier {
 		MessageDigest messageDigest = crypto.getMessageDigest();
 		Signature signature = crypto.getSignature();
 		// Reject the message if it's too far in the future
-		if(m.getTimestamp() > clock.currentTimeMillis() + MAX_CLOCK_DIFFERENCE)
+		if (m.getTimestamp() > clock.currentTimeMillis() + MAX_CLOCK_DIFFERENCE)
 			throw new GeneralSecurityException();
 		// Hash the message to get the message ID
 		byte[] raw = m.getSerialised();
@@ -50,18 +50,18 @@ class MessageVerifierImpl implements MessageVerifier {
 		MessageId id = new MessageId(messageDigest.digest());
 		// Verify the author's signature, if there is one
 		Author author = m.getAuthor();
-		if(author != null) {
+		if (author != null) {
 			PublicKey k = keyParser.parsePublicKey(author.getPublicKey());
 			signature.initVerify(k);
 			signature.update(raw, 0, m.getSignedLength());
-			if(!signature.verify(m.getSignature()))
+			if (!signature.verify(m.getSignature()))
 				throw new GeneralSecurityException();
 		}
 		Message verified = new MessageImpl(id, m.getParent(), m.getGroup(),
 				author, m.getContentType(), m.getTimestamp(), raw,
 				m.getBodyStart(), m.getBodyLength());
 		long duration = System.currentTimeMillis() - now;
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Verifying message took " + duration + " ms");
 		return verified;
 	}
diff --git a/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java b/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java
index e5d2845b46..a18b86e905 100644
--- a/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java
+++ b/briar-core/src/org/briarproject/messaging/PacketReaderImpl.java
@@ -77,32 +77,32 @@ class PacketReaderImpl implements PacketReader {
 		assert state == State.BUFFER_EMPTY;
 		// Read the header
 		int offset = 0;
-		while(offset < HEADER_LENGTH) {
+		while (offset < HEADER_LENGTH) {
 			int read = in.read(header, offset, HEADER_LENGTH - offset);
-			if(read == -1) {
-				if(offset > 0) throw new FormatException();
+			if (read == -1) {
+				if (offset > 0) throw new FormatException();
 				state = State.EOF;
 				return;
 			}
 			offset += read;
 		}
 		// Check the protocol version
-		if(header[0] != PROTOCOL_VERSION) throw new FormatException();
+		if (header[0] != PROTOCOL_VERSION) throw new FormatException();
 		// Read the payload length
 		payloadLength = ByteUtils.readUint16(header, 2);
-		if(payloadLength > MAX_PAYLOAD_LENGTH) throw new FormatException();
+		if (payloadLength > MAX_PAYLOAD_LENGTH) throw new FormatException();
 		// Read the payload
 		offset = 0;
-		while(offset < payloadLength) {
+		while (offset < payloadLength) {
 			int read = in.read(payload, offset, payloadLength - offset);
-			if(read == -1) throw new FormatException();
+			if (read == -1) throw new FormatException();
 			offset += read;
 		}
 		state = State.BUFFER_FULL;
 	}
 
 	public boolean eof() throws IOException {
-		if(state == State.BUFFER_EMPTY) readPacket();
+		if (state == State.BUFFER_EMPTY) readPacket();
 		assert state != State.BUFFER_EMPTY;
 		return state == State.EOF;
 	}
@@ -112,7 +112,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public Ack readAck() throws IOException {
-		if(!hasAck()) throw new FormatException();
+		if (!hasAck()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -121,17 +121,17 @@ class PacketReaderImpl implements PacketReader {
 		// Read the message IDs
 		List<MessageId> acked = new ArrayList<MessageId>();
 		r.readListStart();
-		while(!r.hasListEnd()) {
+		while (!r.hasListEnd()) {
 			byte[] b = r.readRaw(UniqueId.LENGTH);
-			if(b.length != UniqueId.LENGTH)
+			if (b.length != UniqueId.LENGTH)
 				throw new FormatException();
 			acked.add(new MessageId(b));
 		}
-		if(acked.isEmpty()) throw new FormatException();
+		if (acked.isEmpty()) throw new FormatException();
 		r.readListEnd();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the ack
 		return new Ack(Collections.unmodifiableList(acked));
@@ -142,13 +142,13 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public UnverifiedMessage readMessage() throws IOException {
-		if(!hasMessage()) throw new FormatException();
+		if (!hasMessage()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
 		// Read and build the message
 		UnverifiedMessage m = messageReader.readObject(r);
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		return m;
 	}
@@ -158,7 +158,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public Offer readOffer() throws IOException {
-		if(!hasOffer()) throw new FormatException();
+		if (!hasOffer()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -167,17 +167,17 @@ class PacketReaderImpl implements PacketReader {
 		// Read the message IDs
 		List<MessageId> offered = new ArrayList<MessageId>();
 		r.readListStart();
-		while(!r.hasListEnd()) {
+		while (!r.hasListEnd()) {
 			byte[] b = r.readRaw(UniqueId.LENGTH);
-			if(b.length != UniqueId.LENGTH)
+			if (b.length != UniqueId.LENGTH)
 				throw new FormatException();
 			offered.add(new MessageId(b));
 		}
-		if(offered.isEmpty()) throw new FormatException();
+		if (offered.isEmpty()) throw new FormatException();
 		r.readListEnd();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the offer
 		return new Offer(Collections.unmodifiableList(offered));
@@ -188,7 +188,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public Request readRequest() throws IOException {
-		if(!hasRequest()) throw new FormatException();
+		if (!hasRequest()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -197,17 +197,17 @@ class PacketReaderImpl implements PacketReader {
 		// Read the message IDs
 		r.readListStart();
 		List<MessageId> requested = new ArrayList<MessageId>();
-		while(!r.hasListEnd()) {
+		while (!r.hasListEnd()) {
 			byte[] b = r.readRaw(UniqueId.LENGTH);
-			if(b.length != UniqueId.LENGTH)
+			if (b.length != UniqueId.LENGTH)
 				throw new FormatException();
 			requested.add(new MessageId(b));
 		}
-		if(requested.isEmpty()) throw new FormatException();
+		if (requested.isEmpty()) throw new FormatException();
 		r.readListEnd();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the request
 		return new Request(Collections.unmodifiableList(requested));
@@ -218,7 +218,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public RetentionAck readRetentionAck() throws IOException {
-		if(!hasRetentionAck()) throw new FormatException();
+		if (!hasRetentionAck()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -226,10 +226,10 @@ class PacketReaderImpl implements PacketReader {
 		r.readListStart();
 		// Read the version
 		long version = r.readInteger();
-		if(version < 0) throw new FormatException();
+		if (version < 0) throw new FormatException();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the retention ack
 		return new RetentionAck(version);
@@ -240,7 +240,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public RetentionUpdate readRetentionUpdate() throws IOException {
-		if(!hasRetentionUpdate()) throw new FormatException();
+		if (!hasRetentionUpdate()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -248,12 +248,12 @@ class PacketReaderImpl implements PacketReader {
 		r.readListStart();
 		// Read the retention time and version
 		long retention = r.readInteger();
-		if(retention < 0) throw new FormatException();
+		if (retention < 0) throw new FormatException();
 		long version = r.readInteger();
-		if(version < 0) throw new FormatException();
+		if (version < 0) throw new FormatException();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the retention update
 		return new RetentionUpdate(retention, version);
@@ -264,7 +264,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public SubscriptionAck readSubscriptionAck() throws IOException {
-		if(!hasSubscriptionAck()) throw new FormatException();
+		if (!hasSubscriptionAck()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -272,10 +272,10 @@ class PacketReaderImpl implements PacketReader {
 		r.readListStart();
 		// Read the version
 		long version = r.readInteger();
-		if(version < 0) throw new FormatException();
+		if (version < 0) throw new FormatException();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the subscription ack
 		return new SubscriptionAck(version);
@@ -286,13 +286,13 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public SubscriptionUpdate readSubscriptionUpdate() throws IOException {
-		if(!hasSubscriptionUpdate()) throw new FormatException();
+		if (!hasSubscriptionUpdate()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
 		// Read and build the subscription update
 		SubscriptionUpdate u = subscriptionUpdateReader.readObject(r);
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		return u;
 	}
@@ -302,7 +302,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public TransportAck readTransportAck() throws IOException {
-		if(!hasTransportAck()) throw new FormatException();
+		if (!hasTransportAck()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -310,13 +310,13 @@ class PacketReaderImpl implements PacketReader {
 		r.readListStart();
 		// Read the transport ID and version
 		String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
-		if(idString.length() == 0) throw new FormatException();
+		if (idString.length() == 0) throw new FormatException();
 		TransportId id = new TransportId(idString);
 		long version = r.readInteger();
-		if(version < 0) throw new FormatException();
+		if (version < 0) throw new FormatException();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the transport ack
 		return new TransportAck(id, version);
@@ -327,7 +327,7 @@ class PacketReaderImpl implements PacketReader {
 	}
 
 	public TransportUpdate readTransportUpdate() throws IOException {
-		if(!hasTransportUpdate()) throw new FormatException();
+		if (!hasTransportUpdate()) throw new FormatException();
 		// Set up the reader
 		InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
 		Reader r = readerFactory.createReader(bais);
@@ -335,13 +335,13 @@ class PacketReaderImpl implements PacketReader {
 		r.readListStart();
 		// Read the transport ID
 		String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
-		if(idString.length() == 0) throw new FormatException();
+		if (idString.length() == 0) throw new FormatException();
 		TransportId id = new TransportId(idString);
 		// Read the transport properties
 		Map<String, String> p = new HashMap<String, String>();
 		r.readMapStart();
-		for(int i = 0; !r.hasMapEnd(); i++) {
-			if(i == MAX_PROPERTIES_PER_TRANSPORT)
+		for (int i = 0; !r.hasMapEnd(); i++) {
+			if (i == MAX_PROPERTIES_PER_TRANSPORT)
 				throw new FormatException();
 			String key = r.readString(MAX_PROPERTY_LENGTH);
 			String value = r.readString(MAX_PROPERTY_LENGTH);
@@ -350,10 +350,10 @@ class PacketReaderImpl implements PacketReader {
 		r.readMapEnd();
 		// Read the version number
 		long version = r.readInteger();
-		if(version < 0) throw new FormatException();
+		if (version < 0) throw new FormatException();
 		// Read the end of the payload
 		r.readListEnd();
-		if(!r.eof()) throw new FormatException();
+		if (!r.eof()) throw new FormatException();
 		state = State.BUFFER_EMPTY;
 		// Build and return the transport update
 		return new TransportUpdate(id, new TransportProperties(p), version);
diff --git a/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java b/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java
index b084e01d6f..ced4d41791 100644
--- a/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java
+++ b/briar-core/src/org/briarproject/messaging/PacketWriterImpl.java
@@ -85,7 +85,7 @@ class PacketWriterImpl implements PacketWriter {
 		Writer w = writerFactory.createWriter(payload);
 		w.writeListStart();
 		w.writeListStart();
-		for(MessageId m : a.getMessageIds()) w.writeRaw(m.getBytes());
+		for (MessageId m : a.getMessageIds()) w.writeRaw(m.getBytes());
 		w.writeListEnd();
 		w.writeListEnd();
 		writePacket(ACK);
@@ -103,7 +103,7 @@ class PacketWriterImpl implements PacketWriter {
 		Writer w = writerFactory.createWriter(payload);
 		w.writeListStart();
 		w.writeListStart();
-		for(MessageId m : o.getMessageIds()) w.writeRaw(m.getBytes());
+		for (MessageId m : o.getMessageIds()) w.writeRaw(m.getBytes());
 		w.writeListEnd();
 		w.writeListEnd();
 		writePacket(OFFER);
@@ -114,7 +114,7 @@ class PacketWriterImpl implements PacketWriter {
 		Writer w = writerFactory.createWriter(payload);
 		w.writeListStart();
 		w.writeListStart();
-		for(MessageId m : r.getMessageIds()) w.writeRaw(m.getBytes());
+		for (MessageId m : r.getMessageIds()) w.writeRaw(m.getBytes());
 		w.writeListEnd();
 		w.writeListEnd();
 		writePacket(REQUEST);
@@ -154,7 +154,7 @@ class PacketWriterImpl implements PacketWriter {
 		Writer w = writerFactory.createWriter(payload);
 		w.writeListStart();
 		w.writeListStart();
-		for(Group g : u.getGroups()) {
+		for (Group g : u.getGroups()) {
 			w.writeListStart();
 			w.writeString(g.getName());
 			w.writeRaw(g.getSalt());
diff --git a/briar-core/src/org/briarproject/messaging/SimplexOutgoingSession.java b/briar-core/src/org/briarproject/messaging/SimplexOutgoingSession.java
index 1a5df4a26e..e77c3308d0 100644
--- a/briar-core/src/org/briarproject/messaging/SimplexOutgoingSession.java
+++ b/briar-core/src/org/briarproject/messaging/SimplexOutgoingSession.java
@@ -88,13 +88,13 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 			dbExecutor.execute(new GenerateBatch());
 			// Write packets until interrupted or no more packets to write
 			try {
-				while(!interrupted) {
+				while (!interrupted) {
 					ThrowingRunnable<IOException> task = writerTasks.take();
-					if(task == CLOSE) break;
+					if (task == CLOSE) break;
 					task.run();
 				}
 				packetWriter.flush();
-			} catch(InterruptedException e) {
+			} catch (InterruptedException e) {
 				LOG.info("Interrupted while waiting for a packet to write");
 				Thread.currentThread().interrupt();
 			}
@@ -109,18 +109,18 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	}
 
 	private void decrementOutstandingQueries() {
-		if(outstandingQueries.decrementAndGet() == 0) writerTasks.add(CLOSE);
+		if (outstandingQueries.decrementAndGet() == 0) writerTasks.add(CLOSE);
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof ContactRemovedEvent) {
+		if (e instanceof ContactRemovedEvent) {
 			ContactRemovedEvent c = (ContactRemovedEvent) e;
-			if(c.getContactId().equals(contactId)) interrupt();
-		} else if(e instanceof ShutdownEvent) {
+			if (c.getContactId().equals(contactId)) interrupt();
+		} else if (e instanceof ShutdownEvent) {
 			interrupt();
-		} else if(e instanceof TransportRemovedEvent) {
+		} else if (e instanceof TransportRemovedEvent) {
 			TransportRemovedEvent t = (TransportRemovedEvent) e;
-			if(t.getTransportId().equals(transportId)) interrupt();
+			if (t.getTransportId().equals(transportId)) interrupt();
 		}
 	}
 
@@ -128,16 +128,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateAck implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			int maxMessages = packetWriter.getMaxMessagesForAck(Long.MAX_VALUE);
 			try {
 				Ack a = db.generateAck(contactId, maxMessages);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated ack: " + (a != null));
-				if(a == null) decrementOutstandingQueries();
+				if (a == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteAck(a));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -153,7 +153,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeAck(ack);
 			LOG.info("Sent ack");
 			dbExecutor.execute(new GenerateAck());
@@ -164,16 +164,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateBatch implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				Collection<byte[]> b = db.generateBatch(contactId,
 						MAX_PAYLOAD_LENGTH, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated batch: " + (b != null));
-				if(b == null) decrementOutstandingQueries();
+				if (b == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteBatch(b));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -189,8 +189,8 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
-			for(byte[] raw : batch) packetWriter.writeMessage(raw);
+			if (interrupted) return;
+			for (byte[] raw : batch) packetWriter.writeMessage(raw);
 			LOG.info("Sent batch");
 			dbExecutor.execute(new GenerateBatch());
 		}
@@ -200,15 +200,15 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateRetentionAck implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				RetentionAck a = db.generateRetentionAck(contactId);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated retention ack: " + (a != null));
-				if(a == null) decrementOutstandingQueries();
+				if (a == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteRetentionAck(a));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -225,7 +225,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeRetentionAck(ack);
 			LOG.info("Sent retention ack");
 			dbExecutor.execute(new GenerateRetentionAck());
@@ -236,16 +236,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateRetentionUpdate implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				RetentionUpdate u =
 						db.generateRetentionUpdate(contactId, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated retention update: " + (u != null));
-				if(u == null) decrementOutstandingQueries();
+				if (u == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteRetentionUpdate(u));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -262,7 +262,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeRetentionUpdate(update);
 			LOG.info("Sent retention update");
 			dbExecutor.execute(new GenerateRetentionUpdate());
@@ -273,15 +273,15 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateSubscriptionAck implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				SubscriptionAck a = db.generateSubscriptionAck(contactId);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated subscription ack: " + (a != null));
-				if(a == null) decrementOutstandingQueries();
+				if (a == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteSubscriptionAck(a));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -298,7 +298,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeSubscriptionAck(ack);
 			LOG.info("Sent subscription ack");
 			dbExecutor.execute(new GenerateSubscriptionAck());
@@ -309,16 +309,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateSubscriptionUpdate implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				SubscriptionUpdate u =
 						db.generateSubscriptionUpdate(contactId, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated subscription update: " + (u != null));
-				if(u == null) decrementOutstandingQueries();
+				if (u == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteSubscriptionUpdate(u));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -335,7 +335,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
+			if (interrupted) return;
 			packetWriter.writeSubscriptionUpdate(update);
 			LOG.info("Sent subscription update");
 			dbExecutor.execute(new GenerateSubscriptionUpdate());
@@ -346,16 +346,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateTransportAcks implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				Collection<TransportAck> acks =
 						db.generateTransportAcks(contactId);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated transport acks: " + (acks != null));
-				if(acks == null) decrementOutstandingQueries();
+				if (acks == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteTransportAcks(acks));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -371,8 +371,8 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
-			for(TransportAck a : acks) packetWriter.writeTransportAck(a);
+			if (interrupted) return;
+			for (TransportAck a : acks) packetWriter.writeTransportAck(a);
 			LOG.info("Sent transport acks");
 			dbExecutor.execute(new GenerateTransportAcks());
 		}
@@ -382,16 +382,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 	private class GenerateTransportUpdates implements Runnable {
 
 		public void run() {
-			if(interrupted) return;
+			if (interrupted) return;
 			try {
 				Collection<TransportUpdate> t =
 						db.generateTransportUpdates(contactId, maxLatency);
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Generated transport updates: " + (t != null));
-				if(t == null) decrementOutstandingQueries();
+				if (t == null) decrementOutstandingQueries();
 				else writerTasks.add(new WriteTransportUpdates(t));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				interrupt();
 			}
 		}
@@ -408,8 +408,8 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
 		}
 
 		public void run() throws IOException {
-			if(interrupted) return;
-			for(TransportUpdate u : updates)
+			if (interrupted) return;
+			for (TransportUpdate u : updates)
 				packetWriter.writeTransportUpdate(u);
 			LOG.info("Sent transport updates");
 			dbExecutor.execute(new GenerateTransportUpdates());
diff --git a/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java b/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java
index 1346b2349f..0632ada965 100644
--- a/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java
+++ b/briar-core/src/org/briarproject/messaging/SubscriptionUpdateReader.java
@@ -36,15 +36,15 @@ class SubscriptionUpdateReader implements ObjectReader<SubscriptionUpdate> {
 		List<Group> groups = new ArrayList<Group>();
 		Set<GroupId> ids = new HashSet<GroupId>();
 		r.readListStart();
-		for(int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++) {
+		for (int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++) {
 			Group g = groupReader.readObject(r);
-			if(!ids.add(g.getId())) throw new FormatException(); // Duplicate
+			if (!ids.add(g.getId())) throw new FormatException(); // Duplicate
 			groups.add(g);
 		}
 		r.readListEnd();
 		// Read the version number
 		long version = r.readInteger();
-		if(version < 0) throw new FormatException();
+		if (version < 0) throw new FormatException();
 		// Read the end of the update
 		r.readListEnd();
 		// Reset the reader
diff --git a/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java b/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java
index b7cb70c1bd..72314e45bb 100644
--- a/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java
+++ b/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java
@@ -84,9 +84,9 @@ class ConnectionManagerImpl implements ConnectionManager {
 		byte[] tag = new byte[TAG_LENGTH];
 		InputStream in = r.getInputStream();
 		int offset = 0;
-		while(offset < tag.length) {
+		while (offset < tag.length) {
 			int read = in.read(tag, offset, tag.length - offset);
-			if(read == -1) throw new EOFException();
+			if (read == -1) throw new EOFException();
 			offset += read;
 		}
 		return tag;
@@ -135,16 +135,16 @@ class ConnectionManagerImpl implements ConnectionManager {
 			try {
 				byte[] tag = readTag(transportId, reader);
 				ctx = tagRecogniser.recogniseTag(transportId, tag);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, false);
 				return;
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, false);
 				return;
 			}
-			if(ctx == null) {
+			if (ctx == null) {
 				LOG.info("Unrecognised tag");
 				disposeReader(true, false);
 				return;
@@ -155,8 +155,8 @@ class ConnectionManagerImpl implements ConnectionManager {
 				// Create and run the incoming session
 				createIncomingSession(ctx, reader).run();
 				disposeReader(false, true);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, true);
 			} finally {
 				connectionRegistry.unregisterConnection(contactId, transportId);
@@ -166,8 +166,8 @@ class ConnectionManagerImpl implements ConnectionManager {
 		private void disposeReader(boolean exception, boolean recognised) {
 			try {
 				reader.dispose(exception, recognised);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
@@ -189,7 +189,7 @@ class ConnectionManagerImpl implements ConnectionManager {
 			// Allocate a stream context
 			StreamContext ctx = keyManager.getStreamContext(contactId,
 					transportId);
-			if(ctx == null) {
+			if (ctx == null) {
 				LOG.warning("Could not allocate stream context");
 				disposeWriter(true);
 				return;
@@ -199,8 +199,8 @@ class ConnectionManagerImpl implements ConnectionManager {
 				// Create and run the outgoing session
 				createSimplexOutgoingSession(ctx, writer).run();
 				disposeWriter(false);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeWriter(true);
 			} finally {
 				connectionRegistry.unregisterConnection(contactId, transportId);
@@ -210,8 +210,8 @@ class ConnectionManagerImpl implements ConnectionManager {
 		private void disposeWriter(boolean exception) {
 			try {
 				writer.dispose(exception);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
@@ -239,16 +239,16 @@ class ConnectionManagerImpl implements ConnectionManager {
 			try {
 				byte[] tag = readTag(transportId, reader);
 				ctx = tagRecogniser.recogniseTag(transportId, tag);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, false);
 				return;
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, false);
 				return;
 			}
-			if(ctx == null) {
+			if (ctx == null) {
 				LOG.info("Unrecognised tag");
 				disposeReader(true, false);
 				return;
@@ -266,8 +266,8 @@ class ConnectionManagerImpl implements ConnectionManager {
 				incomingSession = createIncomingSession(ctx, reader);
 				incomingSession.run();
 				disposeReader(false, true);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, true);
 			} finally {
 				connectionRegistry.unregisterConnection(contactId, transportId);
@@ -278,7 +278,7 @@ class ConnectionManagerImpl implements ConnectionManager {
 			// Allocate a stream context
 			StreamContext ctx = keyManager.getStreamContext(contactId,
 					transportId);
-			if(ctx == null) {
+			if (ctx == null) {
 				LOG.warning("Could not allocate stream context");
 				disposeWriter(true);
 				return;
@@ -288,29 +288,29 @@ class ConnectionManagerImpl implements ConnectionManager {
 				outgoingSession = createDuplexOutgoingSession(ctx, writer);
 				outgoingSession.run();
 				disposeWriter(false);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeWriter(true);
 			}
 		}
 
 		private void disposeReader(boolean exception, boolean recognised) {
-			if(exception && outgoingSession != null)
+			if (exception && outgoingSession != null)
 				outgoingSession.interrupt();
 			try {
 				reader.dispose(exception, recognised);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 
 		private void disposeWriter(boolean exception) {
-			if(exception && incomingSession != null)
+			if (exception && incomingSession != null)
 				incomingSession.interrupt();
 			try {
 				writer.dispose(exception);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
@@ -337,7 +337,7 @@ class ConnectionManagerImpl implements ConnectionManager {
 			// Allocate a stream context
 			StreamContext ctx = keyManager.getStreamContext(contactId,
 					transportId);
-			if(ctx == null) {
+			if (ctx == null) {
 				LOG.warning("Could not allocate stream context");
 				disposeWriter(true);
 				return;
@@ -354,8 +354,8 @@ class ConnectionManagerImpl implements ConnectionManager {
 				outgoingSession = createDuplexOutgoingSession(ctx, writer);
 				outgoingSession.run();
 				disposeWriter(false);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeWriter(true);
 			} finally {
 				connectionRegistry.unregisterConnection(contactId, transportId);
@@ -368,23 +368,23 @@ class ConnectionManagerImpl implements ConnectionManager {
 			try {
 				byte[] tag = readTag(transportId, reader);
 				ctx = tagRecogniser.recogniseTag(transportId, tag);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, true);
 				return;
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, true);
 				return;
 			}
 			// Unrecognised tags are suspicious in this case
-			if(ctx == null) {
+			if (ctx == null) {
 				LOG.warning("Unrecognised tag for returning stream");
 				disposeReader(true, true);
 				return;
 			}
 			// Check that the stream comes from the expected contact
-			if(!ctx.getContactId().equals(contactId)) {
+			if (!ctx.getContactId().equals(contactId)) {
 				LOG.warning("Wrong contact ID for returning stream");
 				disposeReader(true, true);
 				return;
@@ -394,29 +394,29 @@ class ConnectionManagerImpl implements ConnectionManager {
 				incomingSession = createIncomingSession(ctx, reader);
 				incomingSession.run();
 				disposeReader(false, true);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				disposeReader(true, true);
 			}
 		}
 
 		private void disposeReader(boolean exception, boolean recognised) {
-			if(exception && outgoingSession != null)
+			if (exception && outgoingSession != null)
 				outgoingSession.interrupt();
 			try {
 				reader.dispose(exception, recognised);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 
 		private void disposeWriter(boolean exception) {
-			if(exception && incomingSession != null)
+			if (exception && incomingSession != null)
 				incomingSession.interrupt();
 			try {
 				writer.dispose(exception);
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
diff --git a/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java b/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java
index 358f6da43a..fc4f9ecae9 100644
--- a/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java
+++ b/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java
@@ -46,15 +46,15 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
 		synchLock.lock();
 		try {
 			Map<ContactId, Integer> m = connections.get(t);
-			if(m == null) {
+			if (m == null) {
 				m = new HashMap<ContactId, Integer>();
 				connections.put(t, m);
 			}
 			Integer count = m.get(c);
-			if(count == null) m.put(c, 1);
+			if (count == null) m.put(c, 1);
 			else m.put(c, count + 1);
 			count = contactCounts.get(c);
-			if(count == null) {
+			if (count == null) {
 				firstConnection = true;
 				contactCounts.put(c, 1);
 			} else {
@@ -64,7 +64,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
 			synchLock.unlock();
 		}
 
-		if(firstConnection) {
+		if (firstConnection) {
 			LOG.info("Contact connected");
 			eventBus.broadcast(new ContactConnectedEvent(c));
 		}
@@ -76,17 +76,17 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
 		synchLock.lock();
 		try {
 			Map<ContactId, Integer> m = connections.get(t);
-			if(m == null) throw new IllegalArgumentException();
+			if (m == null) throw new IllegalArgumentException();
 			Integer count = m.remove(c);
-			if(count == null) throw new IllegalArgumentException();
-			if(count == 1) {
-				if(m.isEmpty()) connections.remove(t);
+			if (count == null) throw new IllegalArgumentException();
+			if (count == 1) {
+				if (m.isEmpty()) connections.remove(t);
 			} else {
 				m.put(c, count - 1);
 			}
 			count = contactCounts.get(c);
-			if(count == null) throw new IllegalArgumentException();
-			if(count == 1) {
+			if (count == null) throw new IllegalArgumentException();
+			if (count == 1) {
 				lastConnection = true;
 				contactCounts.remove(c);
 			} else {
@@ -96,7 +96,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
 			synchLock.unlock();
 		}
 
-		if(lastConnection) {
+		if (lastConnection) {
 			LOG.info("Contact disconnected");
 			eventBus.broadcast(new ContactDisconnectedEvent(c));
 		}
@@ -107,9 +107,9 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
 		synchLock.lock();
 		try {
 			Map<ContactId, Integer> m = connections.get(t);
-			if(m == null) return Collections.emptyList();
+			if (m == null) return Collections.emptyList();
 			List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
-			if(LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected");
+			if (LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected");
 			return Collections.unmodifiableList(ids);
 		} finally {
 			synchLock.unlock();
diff --git a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java
index e6ea858778..05fe90842f 100644
--- a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java
+++ b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java
@@ -84,20 +84,20 @@ class PluginManagerImpl implements PluginManager {
 		Collection<SimplexPluginFactory> sFactories =
 				simplexPluginConfig.getFactories();
 		final CountDownLatch sLatch = new CountDownLatch(sFactories.size());
-		for(SimplexPluginFactory factory : sFactories)
+		for (SimplexPluginFactory factory : sFactories)
 			ioExecutor.execute(new SimplexPluginStarter(factory, sLatch));
 		// Instantiate and start the duplex plugins
 		LOG.info("Starting duplex plugins");
 		Collection<DuplexPluginFactory> dFactories =
 				duplexPluginConfig.getFactories();
 		final CountDownLatch dLatch = new CountDownLatch(dFactories.size());
-		for(DuplexPluginFactory factory : dFactories)
+		for (DuplexPluginFactory factory : dFactories)
 			ioExecutor.execute(new DuplexPluginStarter(factory, dLatch));
 		// Wait for the plugins to start
 		try {
 			sLatch.await();
 			dLatch.await();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while starting plugins");
 			Thread.currentThread().interrupt();
 			return false;
@@ -112,11 +112,11 @@ class PluginManagerImpl implements PluginManager {
 		final CountDownLatch latch = new CountDownLatch(plugins.size());
 		// Stop the simplex plugins
 		LOG.info("Stopping simplex plugins");
-		for(SimplexPlugin plugin : simplexPlugins)
+		for (SimplexPlugin plugin : simplexPlugins)
 			ioExecutor.execute(new PluginStopper(plugin, latch));
 		// Stop the duplex plugins
 		LOG.info("Stopping duplex plugins");
-		for(DuplexPlugin plugin : duplexPlugins)
+		for (DuplexPlugin plugin : duplexPlugins)
 			ioExecutor.execute(new PluginStopper(plugin, latch));
 		plugins.clear();
 		simplexPlugins.clear();
@@ -124,7 +124,7 @@ class PluginManagerImpl implements PluginManager {
 		// Wait for all the plugins to stop
 		try {
 			latch.await();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while stopping plugins");
 			Thread.currentThread().interrupt();
 			return false;
@@ -138,8 +138,8 @@ class PluginManagerImpl implements PluginManager {
 
 	public Collection<DuplexPlugin> getInvitationPlugins() {
 		List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
-		for(DuplexPlugin d : duplexPlugins)
-			if(d.supportsInvitations()) supported.add(d);
+		for (DuplexPlugin d : duplexPlugins)
+			if (d.supportsInvitations()) supported.add(d);
 		return Collections.unmodifiableList(supported);
 	}
 
@@ -159,8 +159,8 @@ class PluginManagerImpl implements PluginManager {
 				TransportId id = factory.getId();
 				SimplexCallback callback = new SimplexCallback(id);
 				SimplexPlugin plugin = factory.createPlugin(callback);
-				if(plugin == null) {
-					if(LOG.isLoggable(INFO)) {
+				if (plugin == null) {
+					if (LOG.isLoggable(INFO)) {
 						String name = factory.getClass().getSimpleName();
 						LOG.info(name + " did not create a plugin");
 					}
@@ -170,10 +170,10 @@ class PluginManagerImpl implements PluginManager {
 					long start = clock.currentTimeMillis();
 					db.addTransport(id, plugin.getMaxLatency());
 					long duration = clock.currentTimeMillis() - start;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Adding transport took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					return;
 				}
@@ -181,23 +181,23 @@ class PluginManagerImpl implements PluginManager {
 					long start = clock.currentTimeMillis();
 					boolean started = plugin.start();
 					long duration = clock.currentTimeMillis() - start;
-					if(started) {
+					if (started) {
 						plugins.put(id, plugin);
 						simplexPlugins.add(plugin);
-						if(plugin.shouldPoll()) poller.addPlugin(plugin);
-						if(LOG.isLoggable(INFO)) {
+						if (plugin.shouldPoll()) poller.addPlugin(plugin);
+						if (LOG.isLoggable(INFO)) {
 							String name = plugin.getClass().getSimpleName();
 							LOG.info("Starting " + name + " took " +
 									duration + " ms");
 						}
 					} else {
-						if(LOG.isLoggable(WARNING)) {
+						if (LOG.isLoggable(WARNING)) {
 							String name = plugin.getClass().getSimpleName();
 							LOG.warning(name + " did not start");
 						}
 					}
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			} finally {
@@ -222,8 +222,8 @@ class PluginManagerImpl implements PluginManager {
 				TransportId id = factory.getId();
 				DuplexCallback callback = new DuplexCallback(id);
 				DuplexPlugin plugin = factory.createPlugin(callback);
-				if(plugin == null) {
-					if(LOG.isLoggable(INFO)) {
+				if (plugin == null) {
+					if (LOG.isLoggable(INFO)) {
 						String name = factory.getClass().getSimpleName();
 						LOG.info(name + " did not create a plugin");
 					}
@@ -233,10 +233,10 @@ class PluginManagerImpl implements PluginManager {
 					long start = clock.currentTimeMillis();
 					db.addTransport(id, plugin.getMaxLatency());
 					long duration = clock.currentTimeMillis() - start;
-					if(LOG.isLoggable(INFO))
+					if (LOG.isLoggable(INFO))
 						LOG.info("Adding transport took " + duration + " ms");
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					return;
 				}
@@ -244,23 +244,23 @@ class PluginManagerImpl implements PluginManager {
 					long start = clock.currentTimeMillis();
 					boolean started = plugin.start();
 					long duration = clock.currentTimeMillis() - start;
-					if(started) {
+					if (started) {
 						plugins.put(id, plugin);
 						duplexPlugins.add(plugin);
-						if(plugin.shouldPoll()) poller.addPlugin(plugin);
-						if(LOG.isLoggable(INFO)) {
+						if (plugin.shouldPoll()) poller.addPlugin(plugin);
+						if (LOG.isLoggable(INFO)) {
 							String name = plugin.getClass().getSimpleName();
 							LOG.info("Starting " + name + " took " +
 									duration + " ms");
 						}
 					} else {
-						if(LOG.isLoggable(WARNING)) {
+						if (LOG.isLoggable(WARNING)) {
 							String name = plugin.getClass().getSimpleName();
 							LOG.warning(name + " did not start");
 						}
 					}
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			} finally {
@@ -284,12 +284,12 @@ class PluginManagerImpl implements PluginManager {
 				long start = clock.currentTimeMillis();
 				plugin.stop();
 				long duration = clock.currentTimeMillis() - start;
-				if(LOG.isLoggable(INFO)) {
+				if (LOG.isLoggable(INFO)) {
 					String name = plugin.getClass().getSimpleName();
 					LOG.info("Stopping " + name + " took " + duration + " ms");
 				}
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			} finally {
 				latch.countDown();
 			}
@@ -307,8 +307,8 @@ class PluginManagerImpl implements PluginManager {
 		public TransportConfig getConfig() {
 			try {
 				return db.getConfig(id);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				return new TransportConfig();
 			}
 		}
@@ -317,8 +317,8 @@ class PluginManagerImpl implements PluginManager {
 			try {
 				TransportProperties p = db.getLocalProperties(id);
 				return p == null ? new TransportProperties() : p;
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				return new TransportProperties();
 			}
 		}
@@ -326,8 +326,8 @@ class PluginManagerImpl implements PluginManager {
 		public Map<ContactId, TransportProperties> getRemoteProperties() {
 			try {
 				return db.getRemoteProperties(id);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				return Collections.emptyMap();
 			}
 		}
@@ -335,16 +335,16 @@ class PluginManagerImpl implements PluginManager {
 		public void mergeConfig(TransportConfig c) {
 			try {
 				db.mergeConfig(id, c);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 
 		public void mergeLocalProperties(TransportProperties p) {
 			try {
 				db.mergeLocalProperties(id, p);
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 
@@ -362,7 +362,7 @@ class PluginManagerImpl implements PluginManager {
 
 		public void pollNow() {
 			Plugin p = plugins.get(id);
-			if(p != null) poller.pollNow(p);
+			if (p != null) poller.pollNow(p);
 		}
 	}
 
diff --git a/briar-core/src/org/briarproject/plugins/PollerImpl.java b/briar-core/src/org/briarproject/plugins/PollerImpl.java
index 1d3ede42ce..38f79f7254 100644
--- a/briar-core/src/org/briarproject/plugins/PollerImpl.java
+++ b/briar-core/src/org/briarproject/plugins/PollerImpl.java
@@ -41,14 +41,14 @@ class PollerImpl implements Poller {
 	private void schedule(Plugin plugin, boolean randomise) {
 		long interval = plugin.getPollingInterval();
 		// Randomise intervals at startup to spread out connection attempts
-		if(randomise) interval = (long) (interval * Math.random());
+		if (randomise) interval = (long) (interval * Math.random());
 		timer.schedule(new PollTask(plugin), interval);
 	}
 
 	public void pollNow(final Plugin p) {
 		ioExecutor.execute(new Runnable() {
 			public void run() {
-				if(LOG.isLoggable(INFO))
+				if (LOG.isLoggable(INFO))
 					LOG.info("Polling " + p.getClass().getSimpleName());
 				p.poll(connectionRegistry.getConnectedContacts(p.getId()));
 			}
diff --git a/briar-core/src/org/briarproject/plugins/file/FilePlugin.java b/briar-core/src/org/briarproject/plugins/file/FilePlugin.java
index abaa634925..9f32a535f1 100644
--- a/briar-core/src/org/briarproject/plugins/file/FilePlugin.java
+++ b/briar-core/src/org/briarproject/plugins/file/FilePlugin.java
@@ -62,13 +62,13 @@ public abstract class FilePlugin implements SimplexPlugin {
 	}
 
 	public TransportConnectionWriter createWriter(ContactId c) {
-		if(!running) return null;
+		if (!running) return null;
 		return createWriter(createConnectionFilename());
 	}
 
 	private String createConnectionFilename() {
 		StringBuilder s = new StringBuilder(12);
-		for(int i = 0; i < 8; i++) s.append((char) ('a' + Math.random() * 26));
+		for (int i = 0; i < 8; i++) s.append((char) ('a' + Math.random() * 26));
 		s.append(".dat");
 		return s.toString();
 	}
@@ -79,24 +79,24 @@ public abstract class FilePlugin implements SimplexPlugin {
 	}
 
 	private TransportConnectionWriter createWriter(String filename) {
-		if(!running) return null;
+		if (!running) return null;
 		File dir = chooseOutputDirectory();
-		if(dir == null || !dir.exists() || !dir.isDirectory()) return null;
+		if (dir == null || !dir.exists() || !dir.isDirectory()) return null;
 		File f = new File(dir, filename);
 		try {
 			long capacity = fileUtils.getFreeSpace(dir);
-			if(capacity < MIN_STREAM_LENGTH) return null;
+			if (capacity < MIN_STREAM_LENGTH) return null;
 			OutputStream out = new FileOutputStream(f);
 			return new FileTransportWriter(f, out, capacity, this);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			f.delete();
 			return null;
 		}
 	}
 
 	protected void createReaderFromFile(final File f) {
-		if(!running) return;
+		if (!running) return;
 		ioExecutor.execute(new ReaderCreator(f));
 	}
 
@@ -109,13 +109,13 @@ public abstract class FilePlugin implements SimplexPlugin {
 		}
 
 		public void run() {
-			if(isPossibleConnectionFilename(file.getName())) {
+			if (isPossibleConnectionFilename(file.getName())) {
 				try {
 					FileInputStream in = new FileInputStream(file);
 					callback.readerCreated(new FileTransportReader(file, in,
 							FilePlugin.this));
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 				}
 			}
diff --git a/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java b/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java
index 4c434faa62..39ea14b3ea 100644
--- a/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java
+++ b/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java
@@ -35,10 +35,10 @@ class FileTransportReader implements TransportConnectionReader {
 	public void dispose(boolean exception, boolean recognised) {
 		try {
 			in.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
-		if(recognised) {
+		if (recognised) {
 			file.delete();
 			plugin.readerFinished(file);
 		}
diff --git a/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java b/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java
index f9b14651e1..94e83fe5b8 100644
--- a/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java
+++ b/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java
@@ -46,10 +46,10 @@ class FileTransportWriter implements TransportConnectionWriter {
 	public void dispose(boolean exception) {
 		try {
 			out.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
-		if(exception) file.delete();
+		if (exception) file.delete();
 		else plugin.writerFinished(file);
 	}
 }
diff --git a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java
index ea030c40ee..07dfac5174 100644
--- a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java
+++ b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java
@@ -32,10 +32,10 @@ class LanTcpPlugin extends TcpPlugin {
 		String oldAddress = p.get("address"), oldPort = p.get("port");
 		InetSocketAddress old = parseSocketAddress(oldAddress, oldPort);
 		List<SocketAddress> addrs = new LinkedList<SocketAddress>();
-		for(InetAddress a : getLocalIpAddresses()) {
-			if(isAcceptableAddress(a)) {
+		for (InetAddress a : getLocalIpAddresses()) {
+			if (isAcceptableAddress(a)) {
 				// If this is the old address, try to use the same port
-				if(old != null && old.getAddress().equals(a))
+				if (old != null && old.getAddress().equals(a))
 					addrs.add(0, new InetSocketAddress(a, old.getPort()));
 				addrs.add(new InetSocketAddress(a, 0));
 			}
@@ -54,10 +54,10 @@ class LanTcpPlugin extends TcpPlugin {
 
 	@Override
 	protected boolean isConnectable(InetSocketAddress remote) {
-		if(remote.getPort() == 0) return false;
-		if(!isAcceptableAddress(remote.getAddress())) return false;
+		if (remote.getPort() == 0) return false;
+		if (!isAcceptableAddress(remote.getAddress())) return false;
 		// Try to determine whether the address is on the same LAN as us
-		if(socket == null) return false;
+		if (socket == null) return false;
 		byte[] localIp = socket.getInetAddress().getAddress();
 		byte[] remoteIp = remote.getAddress().getAddress();
 		return addressesAreOnSameLan(localIp, remoteIp);
@@ -66,12 +66,12 @@ class LanTcpPlugin extends TcpPlugin {
 	// Package access for testing
 	boolean addressesAreOnSameLan(byte[] localIp, byte[] remoteIp) {
 		// 10.0.0.0/8
-		if(localIp[0] == 10) return remoteIp[0] == 10;
+		if (localIp[0] == 10) return remoteIp[0] == 10;
 		// 172.16.0.0/12
-		if(localIp[0] == (byte) 172 && (localIp[1] & 0xF0) == 16)
+		if (localIp[0] == (byte) 172 && (localIp[1] & 0xF0) == 16)
 			return remoteIp[0] == (byte) 172 && (remoteIp[1] & 0xF0) == 16;
 		// 192.168.0.0/16
-		if(localIp[0] == (byte) 192 && localIp[1] == (byte) 168)
+		if (localIp[0] == (byte) 192 && localIp[1] == (byte) 168)
 			return remoteIp[0] == (byte) 192 && remoteIp[1] == (byte) 168;
 		// Unrecognised prefix - may be compatible
 		return true;
diff --git a/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java b/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java
index 5ac8251fc7..a1585b6bec 100644
--- a/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java
+++ b/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java
@@ -30,18 +30,18 @@ class PortMapperImpl implements PortMapper {
 	}
 
 	public MappingResult map(final int port) {
-		if(!started.getAndSet(true)) start();
-		if(gateway == null) return null;
+		if (!started.getAndSet(true)) start();
+		if (gateway == null) return null;
 		InetAddress internal = gateway.getLocalAddress();
-		if(internal == null) return null;
-		if(LOG.isLoggable(INFO))
+		if (internal == null) return null;
+		if (LOG.isLoggable(INFO))
 			LOG.info("Internal address " + getHostAddress(internal));
 		boolean succeeded = false;
 		InetAddress external = null;
 		try {
 			succeeded = gateway.addPortMapping(port, port,
 					getHostAddress(internal), "TCP", "TCP");
-			if(succeeded) {
+			if (succeeded) {
 				shutdownManager.addShutdownHook(new Runnable() {
 					public void run() {
 						deleteMapping(port);
@@ -49,14 +49,14 @@ class PortMapperImpl implements PortMapper {
 				});
 			}
 			String externalString = gateway.getExternalIPAddress();
-			if(LOG.isLoggable(INFO))
+			if (LOG.isLoggable(INFO))
 				LOG.info("External address " + externalString);
-			if(externalString != null)
+			if (externalString != null)
 				external = InetAddress.getByName(externalString);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(SAXException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (SAXException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		return new MappingResult(internal, external, port, succeeded);
 	}
@@ -64,7 +64,7 @@ class PortMapperImpl implements PortMapper {
 	private String getHostAddress(InetAddress a) {
 		String addr = a.getHostAddress();
 		int percent = addr.indexOf('%');
-		if(percent == -1) return addr;
+		if (percent == -1) return addr;
 		return addr.substring(0, percent);
 	}
 
@@ -72,12 +72,12 @@ class PortMapperImpl implements PortMapper {
 		GatewayDiscover d = new GatewayDiscover();
 		try {
 			d.discover();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(SAXException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(ParserConfigurationException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (SAXException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (ParserConfigurationException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		gateway = d.getValidGateway();
 	}
@@ -85,12 +85,12 @@ class PortMapperImpl implements PortMapper {
 	private void deleteMapping(int port) {
 		try {
 			gateway.deletePortMapping(port, "TCP");
-			if(LOG.isLoggable(INFO))
+			if (LOG.isLoggable(INFO))
 				LOG.info("Deleted mapping for port " + port); 
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		} catch(SAXException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (SAXException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 }
diff --git a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java
index 083f46598d..369b5a6d28 100644
--- a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java
+++ b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java
@@ -58,7 +58,7 @@ abstract class TcpPlugin implements DuplexPlugin {
 		this.maxLatency = maxLatency;
 		this.maxIdleTime = maxIdleTime;
 		this.pollingInterval = pollingInterval;
-		if(maxIdleTime > Integer.MAX_VALUE / 2)
+		if (maxIdleTime > Integer.MAX_VALUE / 2)
 			socketTimeout = Integer.MAX_VALUE;
 		else socketTimeout = maxIdleTime * 2;
 	}
@@ -80,32 +80,32 @@ abstract class TcpPlugin implements DuplexPlugin {
 	protected void bind() {
 		ioExecutor.execute(new Runnable() {
 			public void run() {
-				if(!running) return;
+				if (!running) return;
 				ServerSocket ss = null;
-				for(SocketAddress addr : getLocalSocketAddresses()) {
+				for (SocketAddress addr : getLocalSocketAddresses()) {
 					try {
 						ss = new ServerSocket();
 						ss.bind(addr);
 						break;
-					} catch(IOException e) {
-						if(LOG.isLoggable(INFO))
+					} catch (IOException e) {
+						if (LOG.isLoggable(INFO))
 							LOG.info("Failed to bind " + addr);
 						tryToClose(ss);
 						continue;
 					}
 				}
-				if(ss == null || !ss.isBound()) {
+				if (ss == null || !ss.isBound()) {
 					LOG.info("Could not bind server socket");
 					return;
 				}
-				if(!running) {
+				if (!running) {
 					tryToClose(ss);
 					return;
 				}
 				socket = ss;
 				SocketAddress local = ss.getLocalSocketAddress();
 				setLocalSocketAddress((InetSocketAddress) local);
-				if(LOG.isLoggable(INFO)) LOG.info("Listening on " + local);
+				if (LOG.isLoggable(INFO)) LOG.info("Listening on " + local);
 				callback.pollNow();
 				acceptContactConnections();
 			}
@@ -114,9 +114,9 @@ abstract class TcpPlugin implements DuplexPlugin {
 
 	protected void tryToClose(ServerSocket ss) {
 		try {
-			if(ss != null) ss.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (ss != null) ss.close();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
@@ -134,17 +134,17 @@ abstract class TcpPlugin implements DuplexPlugin {
 	}
 
 	private void acceptContactConnections() {
-		while(isRunning()) {
+		while (isRunning()) {
 			Socket s;
 			try {
 				s = socket.accept();
 				s.setSoTimeout(socketTimeout);
-			} catch(IOException e) {
+			} catch (IOException e) {
 				// This is expected when the socket is closed
-				if(LOG.isLoggable(INFO)) LOG.info(e.toString());
+				if (LOG.isLoggable(INFO)) LOG.info(e.toString());
 				return;
 			}
-			if(LOG.isLoggable(INFO))
+			if (LOG.isLoggable(INFO))
 				LOG.info("Connection from " + s.getRemoteSocketAddress());
 			TcpTransportConnection conn = new TcpTransportConnection(this, s);
 			callback.incomingConnectionCreated(conn);
@@ -169,26 +169,26 @@ abstract class TcpPlugin implements DuplexPlugin {
 	}
 
 	public void poll(Collection<ContactId> connected) {
-		if(!isRunning()) return;
-		for(ContactId c : callback.getRemoteProperties().keySet())
-			if(!connected.contains(c)) connectAndCallBack(c);
+		if (!isRunning()) return;
+		for (ContactId c : callback.getRemoteProperties().keySet())
+			if (!connected.contains(c)) connectAndCallBack(c);
 	}
 
 	private void connectAndCallBack(final ContactId c) {
 		ioExecutor.execute(new Runnable() {
 			public void run() {
 				DuplexTransportConnection d = createConnection(c);
-				if(d != null) callback.outgoingConnectionCreated(c, d);
+				if (d != null) callback.outgoingConnectionCreated(c, d);
 			}
 		});
 	}
 
 	public DuplexTransportConnection createConnection(ContactId c) {
-		if(!isRunning()) return null;
+		if (!isRunning()) return null;
 		InetSocketAddress remote = getRemoteSocketAddress(c);
-		if(remote == null) return null;
-		if(!isConnectable(remote)) {
-			if(LOG.isLoggable(INFO)) {
+		if (remote == null) return null;
+		if (!isConnectable(remote)) {
+			if (LOG.isLoggable(INFO)) {
 				SocketAddress local = socket.getLocalSocketAddress();
 				LOG.info(remote + " is not connectable from " + local);
 			}
@@ -196,37 +196,37 @@ abstract class TcpPlugin implements DuplexPlugin {
 		}
 		Socket s = new Socket();
 		try {
-			if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + remote);
+			if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + remote);
 			s.connect(remote);
 			s.setSoTimeout(socketTimeout);
-			if(LOG.isLoggable(INFO)) LOG.info("Connected to " + remote);
+			if (LOG.isLoggable(INFO)) LOG.info("Connected to " + remote);
 			return new TcpTransportConnection(this, s);
-		} catch(IOException e) {
-			if(LOG.isLoggable(INFO)) LOG.info("Could not connect to " + remote);
+		} catch (IOException e) {
+			if (LOG.isLoggable(INFO)) LOG.info("Could not connect to " + remote);
 			return null;
 		}
 	}
 
 	private InetSocketAddress getRemoteSocketAddress(ContactId c) {
 		TransportProperties p = callback.getRemoteProperties().get(c);
-		if(p == null) return null;
+		if (p == null) return null;
 		return parseSocketAddress(p.get("address"), p.get("port"));
 	}
 
 	protected InetSocketAddress parseSocketAddress(String addr, String port) {
-		if(StringUtils.isNullOrEmpty(addr)) return null;
-		if(StringUtils.isNullOrEmpty(port)) return null;
+		if (StringUtils.isNullOrEmpty(addr)) return null;
+		if (StringUtils.isNullOrEmpty(port)) return null;
 		// Ensure getByName() won't perform a DNS lookup
-		if(!DOTTED_QUAD.matcher(addr).matches()) return null;
+		if (!DOTTED_QUAD.matcher(addr).matches()) return null;
 		try {
 			InetAddress a = InetAddress.getByName(addr);
 			int p = Integer.parseInt(port);
 			return new InetSocketAddress(a, p);
-		} catch(UnknownHostException e) {
-			if(LOG.isLoggable(WARNING)) LOG.warning("Invalid address: " + addr);
+		} catch (UnknownHostException e) {
+			if (LOG.isLoggable(WARNING)) LOG.warning("Invalid address: " + addr);
 			return null;
-		} catch(NumberFormatException e) {
-			if(LOG.isLoggable(WARNING)) LOG.warning("Invalid port: " + port);
+		} catch (NumberFormatException e) {
+			if (LOG.isLoggable(WARNING)) LOG.warning("Invalid port: " + port);
 			return null;
 		}
 	}
@@ -244,12 +244,12 @@ abstract class TcpPlugin implements DuplexPlugin {
 		List<NetworkInterface> ifaces;
 		try {
 			ifaces = Collections.list(NetworkInterface.getNetworkInterfaces());
-		} catch(SocketException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (SocketException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			return Collections.emptyList();
 		}
 		List<InetAddress> addrs = new ArrayList<InetAddress>();
-		for(NetworkInterface iface : ifaces)
+		for (NetworkInterface iface : ifaces)
 			addrs.addAll(Collections.list(iface.getInetAddresses()));
 		return addrs;
 	}
diff --git a/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java b/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java
index aae3c53ba8..213cb88ce5 100644
--- a/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java
+++ b/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java
@@ -48,8 +48,8 @@ class TcpTransportConnection implements DuplexTransportConnection {
 
 		public void dispose(boolean exception, boolean recognised)
 				throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) socket.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) socket.close();
 		}
 	}
 
@@ -72,8 +72,8 @@ class TcpTransportConnection implements DuplexTransportConnection {
 		}
 
 		public void dispose(boolean exception) throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) socket.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) socket.close();
 		}
 	}
 }
diff --git a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java
index 15a4dfde82..d28997c515 100644
--- a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java
+++ b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java
@@ -38,10 +38,10 @@ class WanTcpPlugin extends TcpPlugin {
 		String oldAddress = p.get("address"), oldPort = p.get("port");
 		InetSocketAddress old = parseSocketAddress(oldAddress, oldPort);
 		List<SocketAddress> addrs = new LinkedList<SocketAddress>();
-		for(InetAddress a : getLocalIpAddresses()) {
-			if(isAcceptableAddress(a)) {
+		for (InetAddress a : getLocalIpAddresses()) {
+			if (isAcceptableAddress(a)) {
 				// If this is the old address, try to use the same port
-				if(old != null && old.getAddress().equals(a))
+				if (old != null && old.getAddress().equals(a))
 					addrs.add(0, new InetSocketAddress(a, old.getPort()));
 				addrs.add(new InetSocketAddress(a, 0));
 			}
@@ -49,9 +49,9 @@ class WanTcpPlugin extends TcpPlugin {
 		// Accept interfaces with local addresses that can be port-mapped
 		int port = old == null ? chooseEphemeralPort() : old.getPort();
 		mappingResult = portMapper.map(port);
-		if(mappingResult != null && mappingResult.isUsable()) {
+		if (mappingResult != null && mappingResult.isUsable()) {
 			InetSocketAddress a = mappingResult.getInternal();
-			if(a.getAddress() instanceof Inet4Address) addrs.add(a);
+			if (a.getAddress() instanceof Inet4Address) addrs.add(a);
 		}
 		return addrs;
 	}
@@ -71,15 +71,15 @@ class WanTcpPlugin extends TcpPlugin {
 
 	@Override
 	protected boolean isConnectable(InetSocketAddress remote) {
-		if(remote.getPort() == 0) return false;
+		if (remote.getPort() == 0) return false;
 		return isAcceptableAddress(remote.getAddress());
 	}
 
 	@Override
 	protected void setLocalSocketAddress(InetSocketAddress a) {
-		if(mappingResult != null && mappingResult.isUsable()) {
+		if (mappingResult != null && mappingResult.isUsable()) {
 			// Advertise the external address to contacts
-			if(a.equals(mappingResult.getInternal()))
+			if (a.equals(mappingResult.getInternal()))
 				a = mappingResult.getExternal();
 		}
 		TransportProperties p = new TransportProperties();
diff --git a/briar-core/src/org/briarproject/reliability/Ack.java b/briar-core/src/org/briarproject/reliability/Ack.java
index adff804c94..1f5352c629 100644
--- a/briar-core/src/org/briarproject/reliability/Ack.java
+++ b/briar-core/src/org/briarproject/reliability/Ack.java
@@ -13,7 +13,7 @@ class Ack extends Frame {
 
 	Ack(byte[] buf) {
 		super(buf);
-		if(buf.length != LENGTH) throw new IllegalArgumentException();
+		if (buf.length != LENGTH) throw new IllegalArgumentException();
 		buf[0] = (byte) Frame.ACK_FLAG;
 	}
 
diff --git a/briar-core/src/org/briarproject/reliability/Crc32.java b/briar-core/src/org/briarproject/reliability/Crc32.java
index 59db66df73..1b456fb777 100644
--- a/briar-core/src/org/briarproject/reliability/Crc32.java
+++ b/briar-core/src/org/briarproject/reliability/Crc32.java
@@ -5,10 +5,10 @@ class Crc32 {
 	private static final long[] TABLE = new long[256];
 
 	static {
-		for(int i = 0; i < 256; i++) {
+		for (int i = 0; i < 256; i++) {
 			long c = i;
-			for(int j = 0; j < 8; j++) {
-				if((c & 1) != 0) c = 0xedb88320L ^ (c >> 1);
+			for (int j = 0; j < 8; j++) {
+				if ((c & 1) != 0) c = 0xedb88320L ^ (c >> 1);
 				else c >>= 1;
 			}
 			TABLE[i] = c;
@@ -16,7 +16,7 @@ class Crc32 {
 	}
 
 	private static long update(long c, byte[] b, int off, int len) {
-		for(int i = off; i < off + len; i++)
+		for (int i = off; i < off + len; i++)
 			c = TABLE[(int) ((c ^ b[i]) & 0xff)] ^ (c >> 8);
 		return c;
 	}
diff --git a/briar-core/src/org/briarproject/reliability/Data.java b/briar-core/src/org/briarproject/reliability/Data.java
index 27c8992da0..09edb4e619 100644
--- a/briar-core/src/org/briarproject/reliability/Data.java
+++ b/briar-core/src/org/briarproject/reliability/Data.java
@@ -9,7 +9,7 @@ class Data extends Frame {
 
 	Data(byte[] buf) {
 		super(buf);
-		if(buf.length < MIN_LENGTH || buf.length > MAX_LENGTH)
+		if (buf.length < MIN_LENGTH || buf.length > MAX_LENGTH)
 			throw new IllegalArgumentException();
 	}
 
@@ -18,7 +18,7 @@ class Data extends Frame {
 	}
 
 	void setLastFrame(boolean lastFrame) {
-		if(lastFrame) buf[0] = (byte) Frame.FIN_FLAG;
+		if (lastFrame) buf[0] = (byte) Frame.FIN_FLAG;
 	}
 
 	int getPayloadLength() {
diff --git a/briar-core/src/org/briarproject/reliability/Frame.java b/briar-core/src/org/briarproject/reliability/Frame.java
index fa6256f8de..65d9a4c81a 100644
--- a/briar-core/src/org/briarproject/reliability/Frame.java
+++ b/briar-core/src/org/briarproject/reliability/Frame.java
@@ -48,7 +48,7 @@ abstract class Frame {
 
 	@Override
 	public boolean equals(Object o) {
-		if(o instanceof Frame) {
+		if (o instanceof Frame) {
 			Frame f = (Frame) o;
 			return buf[0] == f.buf[0] &&
 					getSequenceNumber() == f.getSequenceNumber();
diff --git a/briar-core/src/org/briarproject/reliability/Receiver.java b/briar-core/src/org/briarproject/reliability/Receiver.java
index b45bc27484..b45dcfafe7 100644
--- a/briar-core/src/org/briarproject/reliability/Receiver.java
+++ b/briar-core/src/org/briarproject/reliability/Receiver.java
@@ -43,13 +43,13 @@ class Receiver implements ReadHandler {
 		windowLock.lock();
 		try {
 			long now = clock.currentTimeMillis(), end = now + READ_TIMEOUT;
-			while(now < end && valid) {
-				if(dataFrames.isEmpty()) {
+			while (now < end && valid) {
+				if (dataFrames.isEmpty()) {
 					// Wait for a data frame
 					dataFrameAvailable.await(end - now, MILLISECONDS);
 				} else {
 					Data d = dataFrames.first();
-					if(d.getSequenceNumber() == nextSequenceNumber) {
+					if (d.getSequenceNumber() == nextSequenceNumber) {
 						dataFrames.remove(d);
 						// Update the window
 						windowSize += d.getPayloadLength();
@@ -63,7 +63,7 @@ class Receiver implements ReadHandler {
 				}
 				now = clock.currentTimeMillis();
 			}
-			if(valid) throw new IOException("Read timed out");
+			if (valid) throw new IOException("Read timed out");
 			throw new IOException("Connection closed");
 		} finally {
 			windowLock.unlock();
@@ -81,7 +81,7 @@ class Receiver implements ReadHandler {
 	}
 
 	public void handleRead(byte[] b) throws IOException {
-		if(!valid) throw new IOException("Connection closed");
+		if (!valid) throw new IOException("Connection closed");
 		switch(b[0]) {
 		case 0:
 		case Frame.FIN_FLAG:
@@ -99,36 +99,36 @@ class Receiver implements ReadHandler {
 	private void handleData(byte[] b) throws IOException {
 		windowLock.lock();
 		try {
-			if(b.length < Data.MIN_LENGTH || b.length > Data.MAX_LENGTH) {
+			if (b.length < Data.MIN_LENGTH || b.length > Data.MAX_LENGTH) {
 				// Ignore data frame with invalid length
 				return;
 			}
 			Data d = new Data(b);
 			int payloadLength = d.getPayloadLength();
-			if(payloadLength > windowSize) return; // No space in the window
-			if(d.getChecksum() != d.calculateChecksum()) {
+			if (payloadLength > windowSize) return; // No space in the window
+			if (d.getChecksum() != d.calculateChecksum()) {
 				// Ignore data frame with invalid checksum
 				return;
 			}
 			long sequenceNumber = d.getSequenceNumber();
-			if(sequenceNumber == 0) {
+			if (sequenceNumber == 0) {
 				// Window probe
-			} else if(sequenceNumber < nextSequenceNumber) {
+			} else if (sequenceNumber < nextSequenceNumber) {
 				// Duplicate data frame
-			} else if(d.isLastFrame()) {
+			} else if (d.isLastFrame()) {
 				finalSequenceNumber = sequenceNumber;
 				// Remove any data frames with higher sequence numbers
 				Iterator<Data> it = dataFrames.iterator();
-				while(it.hasNext()) {
+				while (it.hasNext()) {
 					Data d1 = it.next();
-					if(d1.getSequenceNumber() >= finalSequenceNumber) it.remove();
+					if (d1.getSequenceNumber() >= finalSequenceNumber) it.remove();
 				}
-				if(dataFrames.add(d)) {
+				if (dataFrames.add(d)) {
 					windowSize -= payloadLength;
 					dataFrameAvailable.signalAll();
 				}
-			} else if(sequenceNumber < finalSequenceNumber) {
-				if(dataFrames.add(d)) {
+			} else if (sequenceNumber < finalSequenceNumber) {
+				if (dataFrames.add(d)) {
 					windowSize -= payloadLength;
 					dataFrameAvailable.signalAll();
 				}
@@ -144,8 +144,8 @@ class Receiver implements ReadHandler {
 
 		public int compare(Data d1, Data d2) {
 			long s1 = d1.getSequenceNumber(), s2 = d2.getSequenceNumber();
-			if(s1 < s2) return -1;
-			if(s1 > s2) return 1;
+			if (s1 < s2) return -1;
+			if (s1 > s2) return 1;
 			return 0;
 		}
 	}
diff --git a/briar-core/src/org/briarproject/reliability/ReceiverInputStream.java b/briar-core/src/org/briarproject/reliability/ReceiverInputStream.java
index 8e10d73be0..ac520f1912 100644
--- a/briar-core/src/org/briarproject/reliability/ReceiverInputStream.java
+++ b/briar-core/src/org/briarproject/reliability/ReceiverInputStream.java
@@ -16,8 +16,8 @@ class ReceiverInputStream extends InputStream {
 
 	@Override
 	public int read() throws IOException {
-		if(length == -1) return -1;
-		while(length == 0) if(!receive()) return -1;
+		if (length == -1) return -1;
+		while (length == 0) if (!receive()) return -1;
 		int b = data.getBuffer()[offset] & 0xff;
 		offset++;
 		length--;
@@ -31,8 +31,8 @@ class ReceiverInputStream extends InputStream {
 
 	@Override
 	public int read(byte[] b, int off, int len) throws IOException {
-		if(length == -1) return -1;
-		while(length == 0) if(!receive()) return -1;
+		if (length == -1) return -1;
+		while (length == 0) if (!receive()) return -1;
 		len = Math.min(len, length);
 		System.arraycopy(data.getBuffer(), offset, b, off, len);
 		offset += len;
@@ -42,13 +42,13 @@ class ReceiverInputStream extends InputStream {
 
 	private boolean receive() throws IOException {
 		assert length == 0;
-		if(data != null && data.isLastFrame()) {
+		if (data != null && data.isLastFrame()) {
 			length = -1;
 			return false;
 		}
 		try {
 			data = receiver.read();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while reading");
 		}
diff --git a/briar-core/src/org/briarproject/reliability/ReliabilityLayerImpl.java b/briar-core/src/org/briarproject/reliability/ReliabilityLayerImpl.java
index 5c0b6a95a5..5058984731 100644
--- a/briar-core/src/org/briarproject/reliability/ReliabilityLayerImpl.java
+++ b/briar-core/src/org/briarproject/reliability/ReliabilityLayerImpl.java
@@ -54,27 +54,27 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
 				long now = clock.currentTimeMillis();
 				long next = now + TICK_INTERVAL;
 				try {
-					while(running) {
+					while (running) {
 						byte[] b = null;
-						while(now < next && b == null) {
+						while (now < next && b == null) {
 							b = writes.poll(next - now, MILLISECONDS);
-							if(!running) return;
+							if (!running) return;
 							now = clock.currentTimeMillis();
 						}
-						if(b == null) {
+						if (b == null) {
 							sender.tick();
-							while(next <= now) next += TICK_INTERVAL;
+							while (next <= now) next += TICK_INTERVAL;
 						} else {
-							if(b.length == 0) return; // Poison pill
+							if (b.length == 0) return; // Poison pill
 							writeHandler.handleWrite(b);
 						}
 					}
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.warning("Interrupted while waiting to write");
 					Thread.currentThread().interrupt();
 					running = false;
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					running = false;
 				}
@@ -98,11 +98,11 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
 
 	// The lower layer calls this method to pass data up to the SLIP decoder
 	public void handleRead(byte[] b) throws IOException {
-		if(running) decoder.handleRead(b);
+		if (running) decoder.handleRead(b);
 	}
 
 	// The SLIP encoder calls this method to pass data down to the lower layer
 	public void handleWrite(byte[] b) {
-		if(running && b.length > 0) writes.add(b);
+		if (running && b.length > 0) writes.add(b);
 	}
 }
diff --git a/briar-core/src/org/briarproject/reliability/Sender.java b/briar-core/src/org/briarproject/reliability/Sender.java
index 6cb5d6d8f4..06d5e3efc8 100644
--- a/briar-core/src/org/briarproject/reliability/Sender.java
+++ b/briar-core/src/org/briarproject/reliability/Sender.java
@@ -53,12 +53,12 @@ class Sender {
 	}
 
 	void handleAck(byte[] b) throws IOException {
-		if(b.length != Ack.LENGTH) {
+		if (b.length != Ack.LENGTH) {
 			// Ignore ack frame with invalid length
 			return;
 		}
 		Ack a = new Ack(b);
-		if(a.getChecksum() != a.calculateChecksum()) {
+		if (a.getChecksum() != a.calculateChecksum()) {
 			// Ignore ack frame with invalid checksum
 			return;
 		}
@@ -70,27 +70,27 @@ class Sender {
 			// Remove the acked data frame if it's outstanding
 			int foundIndex = -1;
 			Iterator<Outstanding> it = outstanding.iterator();
-			for(int i = 0; it.hasNext(); i++) {
+			for (int i = 0; it.hasNext(); i++) {
 				Outstanding o = it.next();
-				if(o.data.getSequenceNumber() == sequenceNumber) {
+				if (o.data.getSequenceNumber() == sequenceNumber) {
 					it.remove();
 					outstandingBytes -= o.data.getPayloadLength();
 					foundIndex = i;
 					// Update the round-trip time and retransmission timeout
-					if(!o.retransmitted) {
+					if (!o.retransmitted) {
 						int sample = (int) (now - o.lastTransmitted);
 						int error = sample - rtt;
 						rtt += (error >> 3);
 						rttVar += (Math.abs(error) - rttVar) >> 2;
 						rto = rtt + (rttVar << 2);
-						if(rto < MIN_RTO) rto = MIN_RTO;
-						else if(rto > MAX_RTO) rto = MAX_RTO;
+						if (rto < MIN_RTO) rto = MIN_RTO;
+						else if (rto > MAX_RTO) rto = MAX_RTO;
 					}
 					break;
 				}
 			}
 			// If any older data frames are outstanding, retransmit the oldest
-			if(foundIndex > 0) {
+			if (foundIndex > 0) {
 				fastRetransmit = outstanding.poll();
 				fastRetransmit.lastTransmitted = now;
 				fastRetransmit.retransmitted = true;
@@ -102,13 +102,13 @@ class Sender {
 			// Don't accept an unreasonably large window size
 			windowSize = Math.min(a.getWindowSize(), MAX_WINDOW_SIZE);
 			// If space has become available, notify any waiting writers
-			if(windowSize > oldWindowSize || foundIndex != -1)
+			if (windowSize > oldWindowSize || foundIndex != -1)
 				sendWindowAvailable.signalAll();
 		} finally {
 			windowLock.unlock();
 		}
 		// Fast retransmission
-		if(fastRetransmit != null)
+		if (fastRetransmit != null)
 			writeHandler.handleWrite(fastRetransmit.data.getBuffer());
 	}
 
@@ -118,28 +118,28 @@ class Sender {
 		boolean sendProbe = false;
 		windowLock.lock();
 		try {
-			if(outstanding.isEmpty()) {
-				if(dataWaiting && now - lastWindowUpdateOrProbe > rto) {
+			if (outstanding.isEmpty()) {
+				if (dataWaiting && now - lastWindowUpdateOrProbe > rto) {
 					sendProbe = true;
 					rto <<= 1;
-					if(rto > MAX_RTO) rto = MAX_RTO;
+					if (rto > MAX_RTO) rto = MAX_RTO;
 				}
 			} else {
 				Iterator<Outstanding> it = outstanding.iterator();
-				while(it.hasNext()) {
+				while (it.hasNext()) {
 					Outstanding o = it.next();
-					if(now - o.lastTransmitted > rto) {
+					if (now - o.lastTransmitted > rto) {
 						it.remove();
-						if(retransmit == null)
+						if (retransmit == null)
 							retransmit = new ArrayList<Outstanding>();
 						retransmit.add(o);
 						// Update the retransmission timeout
 						rto <<= 1;
-						if(rto > MAX_RTO) rto = MAX_RTO;
+						if (rto > MAX_RTO) rto = MAX_RTO;
 					}
 				}
-				if(retransmit != null) {
-					for(Outstanding o : retransmit) {
+				if (retransmit != null) {
+					for (Outstanding o : retransmit) {
 						o.lastTransmitted = now;
 						o.retransmitted = true;
 						outstanding.add(o);
@@ -150,15 +150,15 @@ class Sender {
 			windowLock.unlock();
 		}
 		// Send a window probe if necessary
-		if(sendProbe) {
+		if (sendProbe) {
 			byte[] buf = new byte[Data.MIN_LENGTH];
 			Data probe = new Data(buf);
 			probe.setChecksum(probe.calculateChecksum());
 			writeHandler.handleWrite(buf);
 		}
 		// Retransmit any lost data frames
-		if(retransmit != null) {
-			for(Outstanding o : retransmit)
+		if (retransmit != null) {
+			for (Outstanding o : retransmit)
 				writeHandler.handleWrite(o.data.getBuffer());
 		}
 	}
@@ -169,12 +169,12 @@ class Sender {
 		try {
 			// Wait for space in the window
 			long now = clock.currentTimeMillis(), end = now + WRITE_TIMEOUT;
-			while(now < end && outstandingBytes + payloadLength >= windowSize) {
+			while (now < end && outstandingBytes + payloadLength >= windowSize) {
 				dataWaiting = true;
 				sendWindowAvailable.await(end - now, MILLISECONDS);
 				now = clock.currentTimeMillis();
 			}
-			if(outstandingBytes + payloadLength >= windowSize)
+			if (outstandingBytes + payloadLength >= windowSize)
 				throw new IOException("Write timed out");
 			outstanding.add(new Outstanding(d, now));
 			outstandingBytes += payloadLength;
@@ -188,7 +188,7 @@ class Sender {
 	void flush() throws IOException, InterruptedException {
 		windowLock.lock();
 		try {
-			while(dataWaiting || !outstanding.isEmpty())
+			while (dataWaiting || !outstanding.isEmpty())
 				sendWindowAvailable.await();
 		} finally {
 			windowLock.unlock();
diff --git a/briar-core/src/org/briarproject/reliability/SenderOutputStream.java b/briar-core/src/org/briarproject/reliability/SenderOutputStream.java
index 1cff818821..715fadaff2 100644
--- a/briar-core/src/org/briarproject/reliability/SenderOutputStream.java
+++ b/briar-core/src/org/briarproject/reliability/SenderOutputStream.java
@@ -20,7 +20,7 @@ class SenderOutputStream extends OutputStream {
 		send(true);
 		try {
 			sender.flush();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while closing");
 		}
@@ -28,10 +28,10 @@ class SenderOutputStream extends OutputStream {
 
 	@Override
 	public void flush() throws IOException {
-		if(offset > Data.HEADER_LENGTH) send(false);
+		if (offset > Data.HEADER_LENGTH) send(false);
 		try {
 			sender.flush();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while flushing");
 		}
@@ -41,7 +41,7 @@ class SenderOutputStream extends OutputStream {
 	public void write(int b) throws IOException {
 		buf[offset] = (byte) b;
 		offset++;
-		if(offset == Data.HEADER_LENGTH + Data.MAX_PAYLOAD_LENGTH) send(false);
+		if (offset == Data.HEADER_LENGTH + Data.MAX_PAYLOAD_LENGTH) send(false);
 	}
 
 	@Override
@@ -52,7 +52,7 @@ class SenderOutputStream extends OutputStream {
 	@Override
 	public void write(byte[] b, int off, int len) throws IOException {
 		int available = Data.MAX_LENGTH - offset - Data.FOOTER_LENGTH;
-		while(available <= len) {
+		while (available <= len) {
 			System.arraycopy(b, off, buf, offset, available);
 			offset += available;
 			send(false);
@@ -73,7 +73,7 @@ class SenderOutputStream extends OutputStream {
 		d.setChecksum(d.calculateChecksum());
 		try {
 			sender.write(d);
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while writing");
 		}
diff --git a/briar-core/src/org/briarproject/reliability/SlipDecoder.java b/briar-core/src/org/briarproject/reliability/SlipDecoder.java
index bd6f530f02..3ad966a79b 100644
--- a/briar-core/src/org/briarproject/reliability/SlipDecoder.java
+++ b/briar-core/src/org/briarproject/reliability/SlipDecoder.java
@@ -22,13 +22,13 @@ class SlipDecoder implements ReadHandler {
 	}
 
 	public void handleRead(byte[] b) throws IOException {
-		for(int i = 0; i < b.length; i++) {
+		for (int i = 0; i < b.length; i++) {
 			switch(b[i]) {
 			case END:
-				if(escape) {
+				if (escape) {
 					reset(true);
 				} else {
-					if(decodedLength > 0) {
+					if (decodedLength > 0) {
 						byte[] decoded = new byte[decodedLength];
 						System.arraycopy(buf, 0, decoded, 0, decodedLength);
 						readHandler.handleRead(decoded);
@@ -37,31 +37,31 @@ class SlipDecoder implements ReadHandler {
 				}
 				break;
 			case ESC:
-				if(escape) reset(true);
+				if (escape) reset(true);
 				else escape = true;
 				break;
 			case TEND:
-				if(escape) {
+				if (escape) {
 					escape = false;
-					if(decodedLength == buf.length) reset(true);
+					if (decodedLength == buf.length) reset(true);
 					else buf[decodedLength++] = END;
 				} else {
-					if(decodedLength == buf.length) reset(true);
+					if (decodedLength == buf.length) reset(true);
 					else buf[decodedLength++] = TEND;
 				}
 				break;
 			case TESC:
-				if(escape) {
+				if (escape) {
 					escape = false;
-					if(decodedLength == buf.length) reset(true);
+					if (decodedLength == buf.length) reset(true);
 					else buf[decodedLength++] = ESC;
 				} else {
-					if(decodedLength == buf.length) reset(true);
+					if (decodedLength == buf.length) reset(true);
 					else buf[decodedLength++] = TESC;
 				}
 				break;
 			default:
-				if(escape || decodedLength == buf.length) reset(true);
+				if (escape || decodedLength == buf.length) reset(true);
 				else buf[decodedLength++] = b[i];
 				break;
 			}
diff --git a/briar-core/src/org/briarproject/reliability/SlipEncoder.java b/briar-core/src/org/briarproject/reliability/SlipEncoder.java
index 2cb2959e58..2051f63049 100644
--- a/briar-core/src/org/briarproject/reliability/SlipEncoder.java
+++ b/briar-core/src/org/briarproject/reliability/SlipEncoder.java
@@ -18,15 +18,15 @@ class SlipEncoder implements WriteHandler {
 
 	public void handleWrite(byte[] b) throws IOException {
 		int encodedLength = b.length + 2;
-		for(int i = 0; i < b.length; i++)
-			if(b[i] == END || b[i] == ESC) encodedLength++;
+		for (int i = 0; i < b.length; i++)
+			if (b[i] == END || b[i] == ESC) encodedLength++;
 		byte[] encoded = new byte[encodedLength];
 		encoded[0] = END;
-		for(int i = 0, j = 1; i < b.length; i++) {
-			if(b[i] == END) {
+		for (int i = 0, j = 1; i < b.length; i++) {
+			if (b[i] == END) {
 				encoded[j++] = ESC;
 				encoded[j++] = TEND;
-			} else if(b[i] == ESC) {
+			} else if (b[i] == ESC) {
 				encoded[j++] = ESC;
 				encoded[j++] = TESC;
 			} else {
diff --git a/briar-core/src/org/briarproject/system/LinuxSeedProvider.java b/briar-core/src/org/briarproject/system/LinuxSeedProvider.java
index 49645a776b..58b22d32ad 100644
--- a/briar-core/src/org/briarproject/system/LinuxSeedProvider.java
+++ b/briar-core/src/org/briarproject/system/LinuxSeedProvider.java
@@ -40,9 +40,9 @@ class LinuxSeedProvider implements SeedProvider {
 			writeToEntropyPool(out);
 			out.flush();
 			out.close();
-		} catch(IOException e) {
+		} catch (IOException e) {
 			// On some devices /dev/urandom isn't writable - this isn't fatal
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		// Read the seed from the pool
 		try {
@@ -50,7 +50,7 @@ class LinuxSeedProvider implements SeedProvider {
 					new FileInputStream(inputFile));
 			in.readFully(seed);
 			in.close();
-		} catch(IOException e) {
+		} catch (IOException e) {
 			throw new RuntimeException(e);
 		}
 		return seed;
@@ -61,9 +61,9 @@ class LinuxSeedProvider implements SeedProvider {
 		out.writeLong(System.nanoTime());
 		List<NetworkInterface> ifaces =
 				Collections.list(NetworkInterface.getNetworkInterfaces());
-		for(NetworkInterface i : ifaces) {
+		for (NetworkInterface i : ifaces) {
 			List<InetAddress> addrs = Collections.list(i.getInetAddresses());
-			for(InetAddress a : addrs) out.write(a.getAddress());
+			for (InetAddress a : addrs) out.write(a.getAddress());
 		}
 	}
 }
diff --git a/briar-core/src/org/briarproject/transport/KeyManagerImpl.java b/briar-core/src/org/briarproject/transport/KeyManagerImpl.java
index 257b1ef619..89174c8ff3 100644
--- a/briar-core/src/org/briarproject/transport/KeyManagerImpl.java
+++ b/briar-core/src/org/briarproject/transport/KeyManagerImpl.java
@@ -83,8 +83,8 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 			try {
 				secrets = db.getSecrets();
 				maxLatencies.putAll(db.getTransportLatencies());
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				return false;
 			}
 			// Work out what phase of its lifecycle each secret is in
@@ -93,23 +93,23 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 					assignSecretsToMaps(now, secrets);
 			// Replace any dead secrets
 			Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
-			if(!created.isEmpty()) {
+			if (!created.isEmpty()) {
 				// Store any secrets that have been created,
 				// removing any dead ones
 				try {
 					db.addSecrets(created);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					return false;
 				}
 			}
 			// Pass the old, current and new secrets to the recogniser
-			for(TemporarySecret s : oldSecrets.values())
+			for (TemporarySecret s : oldSecrets.values())
 				tagRecogniser.addSecret(s);
-			for(TemporarySecret s : currentSecrets.values())
+			for (TemporarySecret s : currentSecrets.values())
 				tagRecogniser.addSecret(s);
-			for(TemporarySecret s : newSecrets.values())
+			for (TemporarySecret s : newSecrets.values())
 				tagRecogniser.addSecret(s);
 			// Schedule periodic key rotation
 			timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS,
@@ -125,10 +125,10 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 	private Collection<TemporarySecret> assignSecretsToMaps(long now,
 			Collection<TemporarySecret> secrets) {
 		Collection<TemporarySecret> dead = new ArrayList<TemporarySecret>();
-		for(TemporarySecret s : secrets) {
+		for (TemporarySecret s : secrets) {
 			// Discard the secret if the transport has been removed
 			Integer maxLatency = maxLatencies.get(s.getTransportId());
-			if(maxLatency == null) {
+			if (maxLatency == null) {
 				LOG.info("Discarding obsolete secret");
 				continue;
 			}
@@ -137,13 +137,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 			long activationTime = creationTime + rotation;
 			long deactivationTime = activationTime + rotation;
 			long destructionTime = deactivationTime + rotation;
-			if(now >= destructionTime) {
+			if (now >= destructionTime) {
 				dead.add(s);
-			} else if(now >= deactivationTime) {
+			} else if (now >= deactivationTime) {
 				oldSecrets.put(new EndpointKey(s), s);
-			} else if(now >= activationTime) {
+			} else if (now >= activationTime) {
 				currentSecrets.put(new EndpointKey(s), s);
-			} else if(now >= creationTime) {
+			} else if (now >= creationTime) {
 				newSecrets.put(new EndpointKey(s), s);
 			} else {
 				// FIXME: Work out what to do here
@@ -160,13 +160,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 		// If there are several dead secrets for an endpoint, use the newest
 		Map<EndpointKey, TemporarySecret> newest =
 				new HashMap<EndpointKey, TemporarySecret>();
-		for(TemporarySecret s : dead) {
+		for (TemporarySecret s : dead) {
 			EndpointKey k = new EndpointKey(s);
 			TemporarySecret exists = newest.get(k);
-			if(exists == null) {
+			if (exists == null) {
 				// There's no other secret for this endpoint
 				newest.put(k, s);
-			} else if(exists.getPeriod() < s.getPeriod()) {
+			} else if (exists.getPeriod() < s.getPeriod()) {
 				// There's an older secret - use this one instead
 				newest.put(k, s);
 			} else {
@@ -174,36 +174,36 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 			}
 		}
 		Collection<TemporarySecret> created = new ArrayList<TemporarySecret>();
-		for(Entry<EndpointKey, TemporarySecret> e : newest.entrySet()) {
+		for (Entry<EndpointKey, TemporarySecret> e : newest.entrySet()) {
 			TemporarySecret s = e.getValue();
 			Integer maxLatency = maxLatencies.get(s.getTransportId());
-			if(maxLatency == null) throw new IllegalStateException();
+			if (maxLatency == null) throw new IllegalStateException();
 			// Work out which rotation period we're in
 			long elapsed = now - s.getEpoch();
 			long rotation = maxLatency + MAX_CLOCK_DIFFERENCE;
 			long period = (elapsed / rotation) + 1;
-			if(period < 1) throw new IllegalStateException();
-			if(period - s.getPeriod() < 2)
+			if (period < 1) throw new IllegalStateException();
+			if (period - s.getPeriod() < 2)
 				throw new IllegalStateException();
 			// Derive the old, current and new secrets
 			byte[] b1 = s.getSecret();
-			for(long p = s.getPeriod() + 1; p < period; p++)
+			for (long p = s.getPeriod() + 1; p < period; p++)
 				b1 = crypto.deriveNextSecret(b1, p);
 			byte[] b2 = crypto.deriveNextSecret(b1, period);
 			byte[] b3 = crypto.deriveNextSecret(b2, period + 1);
 			// Add the secrets to their respective maps if not already present
 			EndpointKey k = e.getKey();
-			if(!oldSecrets.containsKey(k)) {
+			if (!oldSecrets.containsKey(k)) {
 				TemporarySecret s1 = new TemporarySecret(s, period - 1, b1);
 				oldSecrets.put(k, s1);
 				created.add(s1);
 			}
-			if(!currentSecrets.containsKey(k)) {
+			if (!currentSecrets.containsKey(k)) {
 				TemporarySecret s2 = new TemporarySecret(s, period, b2);
 				currentSecrets.put(k, s2);
 				created.add(s2);
 			}
-			if(!newSecrets.containsKey(k)) {
+			if (!newSecrets.containsKey(k)) {
 				TemporarySecret s3 = new TemporarySecret(s, period + 1, b3);
 				newSecrets.put(k, s3);
 				created.add(s3);
@@ -233,19 +233,19 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 		synchLock.lock();
 		try {
 			TemporarySecret s = currentSecrets.get(new EndpointKey(c, t));
-			if(s == null) {
+			if (s == null) {
 				LOG.info("No secret for endpoint");
 				return null;
 			}
 			long streamNumber;
 			try {
 				streamNumber = db.incrementStreamCounter(c, t, s.getPeriod());
-				if(streamNumber == -1) {
+				if (streamNumber == -1) {
 					LOG.info("No counter for period");
 					return null;
 				}
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				return null;
 			}
 			byte[] secret = s.getSecret();
@@ -264,10 +264,10 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 			long elapsed = clock.currentTimeMillis() - ep.getEpoch();
 			long rotation = maxLatency + MAX_CLOCK_DIFFERENCE;
 			long period = (elapsed / rotation) + 1;
-			if(period < 1) throw new IllegalStateException();
+			if (period < 1) throw new IllegalStateException();
 			// Derive the old, current and new secrets
 			byte[] b1 = initialSecret;
-			for(long p = 0; p < period; p++)
+			for (long p = 0; p < period; p++)
 				b1 = crypto.deriveNextSecret(b1, p);
 			byte[] b2 = crypto.deriveNextSecret(b1, period);
 			byte[] b3 = crypto.deriveNextSecret(b2, period + 1);
@@ -282,8 +282,8 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 			// Store the new secrets
 			try {
 				db.addSecrets(Arrays.asList(s1, s2, s3));
-			} catch(DbException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (DbException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				return;
 			}
 			// Pass the new secrets to the recogniser
@@ -311,7 +311,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 			long now = clock.currentTimeMillis();
 			Collection<TemporarySecret> dead = assignSecretsToMaps(now, secrets);
 			// Remove any dead secrets from the recogniser
-			for(TemporarySecret s : dead) {
+			for (TemporarySecret s : dead) {
 				ContactId c = s.getContactId();
 				TransportId t = s.getTransportId();
 				long period = s.getPeriod();
@@ -319,15 +319,15 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 			}
 			// Replace any dead secrets
 			Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
-			if(!created.isEmpty()) {
+			if (!created.isEmpty()) {
 				// Store any secrets that have been created
 				try {
 					db.addSecrets(created);
-				} catch(DbException e) {
-					if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				} catch (DbException e) {
+					if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				}
 				// Pass any secrets that have been created to the recogniser
-				for(TemporarySecret s : created) tagRecogniser.addSecret(s);
+				for (TemporarySecret s : created) tagRecogniser.addSecret(s);
 			}
 		} finally {
 			synchLock.unlock();
@@ -335,13 +335,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 	}
 
 	public void eventOccurred(Event e) {
-		if(e instanceof ContactRemovedEvent) {
+		if (e instanceof ContactRemovedEvent) {
 			ContactRemovedEvent c = (ContactRemovedEvent) e;
 			timer.schedule(new ContactRemovedTask(c), 0);
-		} else if(e instanceof TransportAddedEvent) {
+		} else if (e instanceof TransportAddedEvent) {
 			TransportAddedEvent t = (TransportAddedEvent) e;
 			timer.schedule(new TransportAddedTask(t), 0);
-		} else if(e instanceof TransportRemovedEvent) {
+		} else if (e instanceof TransportRemovedEvent) {
 			TransportRemovedEvent t = (TransportRemovedEvent) e;
 			timer.schedule(new TransportRemovedTask(t), 0);
 		}
@@ -350,15 +350,15 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 	// Locking: synchLock
 	private void removeSecrets(ContactId c, Map<?, TemporarySecret> m) {
 		Iterator<TemporarySecret> it = m.values().iterator();
-		while(it.hasNext())
-			if(it.next().getContactId().equals(c)) it.remove();
+		while (it.hasNext())
+			if (it.next().getContactId().equals(c)) it.remove();
 	}
 
 	// Locking: synchLock
 	private void removeSecrets(TransportId t, Map<?, TemporarySecret> m) {
 		Iterator<TemporarySecret> it = m.values().iterator();
-		while(it.hasNext())
-			if(it.next().getTransportId().equals(t)) it.remove();
+		while (it.hasNext())
+			if (it.next().getTransportId().equals(t)) it.remove();
 	}
 
 	private static class EndpointKey {
@@ -382,7 +382,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
 
 		@Override
 		public boolean equals(Object o) {
-			if(o instanceof EndpointKey) {
+			if (o instanceof EndpointKey) {
 				EndpointKey k = (EndpointKey) o;
 				return contactId.equals(k.contactId) &&
 						transportId.equals(k.transportId);
diff --git a/briar-core/src/org/briarproject/transport/ReorderingWindow.java b/briar-core/src/org/briarproject/transport/ReorderingWindow.java
index 951319ddfa..67f82fe24f 100644
--- a/briar-core/src/org/briarproject/transport/ReorderingWindow.java
+++ b/briar-core/src/org/briarproject/transport/ReorderingWindow.java
@@ -17,23 +17,23 @@ class ReorderingWindow {
 
 	ReorderingWindow() {
 		unseen = new HashSet<Long>();
-		for(long l = 0; l < REORDERING_WINDOW_SIZE / 2; l++) unseen.add(l);
+		for (long l = 0; l < REORDERING_WINDOW_SIZE / 2; l++) unseen.add(l);
 		centre = 0;
 	}
 
 	ReorderingWindow(long centre, byte[] bitmap) {
-		if(centre < 0 || centre > MAX_32_BIT_UNSIGNED + 1)
+		if (centre < 0 || centre > MAX_32_BIT_UNSIGNED + 1)
 			throw new IllegalArgumentException();
-		if(bitmap.length != REORDERING_WINDOW_SIZE / 8)
+		if (bitmap.length != REORDERING_WINDOW_SIZE / 8)
 			throw new IllegalArgumentException();
 		this.centre = centre;
 		unseen = new HashSet<Long>();
 		long bitmapBottom = centre - REORDERING_WINDOW_SIZE / 2;
-		for(int bytes = 0; bytes < bitmap.length; bytes++) {
-			for(int bits = 0; bits < 8; bits++) {
+		for (int bytes = 0; bytes < bitmap.length; bytes++) {
+			for (int bits = 0; bits < 8; bits++) {
 				long streamNumber = bitmapBottom + bytes * 8 + bits;
-				if(streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) {
-					if((bitmap[bytes] & (128 >> bits)) == 0)
+				if (streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) {
+					if ((bitmap[bytes] & (128 >> bits)) == 0)
 						unseen.add(streamNumber);
 				}
 			}
@@ -47,20 +47,20 @@ class ReorderingWindow {
 	Collection<Long> setSeen(long streamNumber) {
 		long bottom = getBottom(centre);
 		long top = getTop(centre);
-		if(streamNumber < bottom || streamNumber > top)
+		if (streamNumber < bottom || streamNumber > top)
 			throw new IllegalArgumentException();
-		if(!unseen.remove(streamNumber))
+		if (!unseen.remove(streamNumber))
 			throw new IllegalArgumentException();
 		Collection<Long> changed = new ArrayList<Long>();
-		if(streamNumber >= centre) {
+		if (streamNumber >= centre) {
 			centre = streamNumber + 1;
 			long newBottom = getBottom(centre);
 			long newTop = getTop(centre);
-			for(long l = bottom; l < newBottom; l++) {
-				if(unseen.remove(l)) changed.add(l);
+			for (long l = bottom; l < newBottom; l++) {
+				if (unseen.remove(l)) changed.add(l);
 			}
-			for(long l = top + 1; l <= newTop; l++) {
-				if(unseen.add(l)) changed.add(l);
+			for (long l = top + 1; l <= newTop; l++) {
+				if (unseen.add(l)) changed.add(l);
 			}
 		}
 		return changed;
@@ -73,11 +73,11 @@ class ReorderingWindow {
 	byte[] getBitmap() {
 		byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
 		long bitmapBottom = centre - REORDERING_WINDOW_SIZE / 2;
-		for(int bytes = 0; bytes < bitmap.length; bytes++) {
-			for(int bits = 0; bits < 8; bits++) {
+		for (int bytes = 0; bytes < bitmap.length; bytes++) {
+			for (int bits = 0; bits < 8; bits++) {
 				long streamNumber = bitmapBottom + bytes * 8 + bits;
-				if(streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) {
-					if(!unseen.contains(streamNumber))
+				if (streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) {
+					if (!unseen.contains(streamNumber))
 						bitmap[bytes] |= 128 >> bits;
 				}
 			}
diff --git a/briar-core/src/org/briarproject/transport/StreamReaderImpl.java b/briar-core/src/org/briarproject/transport/StreamReaderImpl.java
index cc94ff505b..002d177237 100644
--- a/briar-core/src/org/briarproject/transport/StreamReaderImpl.java
+++ b/briar-core/src/org/briarproject/transport/StreamReaderImpl.java
@@ -21,8 +21,8 @@ class StreamReaderImpl extends InputStream {
 
 	@Override
 	public int read() throws IOException {
-		while(length <= 0) {
-			if(length == -1) return -1;
+		while (length <= 0) {
+			if (length == -1) return -1;
 			readFrame();
 		}
 		int b = payload[offset] & 0xff;
@@ -38,8 +38,8 @@ class StreamReaderImpl extends InputStream {
 
 	@Override
 	public int read(byte[] b, int off, int len) throws IOException {
-		while(length <= 0) {
-			if(length == -1) return -1;
+		while (length <= 0) {
+			if (length == -1) return -1;
 			readFrame();
 		}
 		len = Math.min(len, length);
diff --git a/briar-core/src/org/briarproject/transport/StreamWriterImpl.java b/briar-core/src/org/briarproject/transport/StreamWriterImpl.java
index 6d7b90ff71..c76e933b59 100644
--- a/briar-core/src/org/briarproject/transport/StreamWriterImpl.java
+++ b/briar-core/src/org/briarproject/transport/StreamWriterImpl.java
@@ -43,7 +43,7 @@ class StreamWriterImpl extends OutputStream {
 	public void write(int b) throws IOException {
 		payload[length] = (byte) b;
 		length++;
-		if(length == payload.length) writeFrame(false);
+		if (length == payload.length) writeFrame(false);
 	}
 
 	@Override
@@ -54,7 +54,7 @@ class StreamWriterImpl extends OutputStream {
 	@Override
 	public void write(byte[] b, int off, int len) throws IOException {
 		int available = payload.length - length;
-		while(available <= len) {
+		while (available <= len) {
 			System.arraycopy(b, off, payload, length, available);
 			length += available;
 			writeFrame(false);
diff --git a/briar-core/src/org/briarproject/transport/TagRecogniserImpl.java b/briar-core/src/org/briarproject/transport/TagRecogniserImpl.java
index ea4e5567b5..1be649bca3 100644
--- a/briar-core/src/org/briarproject/transport/TagRecogniserImpl.java
+++ b/briar-core/src/org/briarproject/transport/TagRecogniserImpl.java
@@ -41,7 +41,7 @@ class TagRecogniserImpl implements TagRecogniser {
 		} finally {
 			synchLock.unlock();
 		}
-		if(r == null) return null;
+		if (r == null) return null;
 		return r.recogniseTag(tag);
 	}
 
@@ -51,7 +51,7 @@ class TagRecogniserImpl implements TagRecogniser {
 		synchLock.lock();
 		try {
 			r = recognisers.get(t);
-			if(r == null) {
+			if (r == null) {
 				r = new TransportTagRecogniser(crypto, db, t);
 				recognisers.put(t, r);
 			}
@@ -69,13 +69,13 @@ class TagRecogniserImpl implements TagRecogniser {
 		} finally {
 			synchLock.unlock();
 		}
-		if(r != null) r.removeSecret(c, period);
+		if (r != null) r.removeSecret(c, period);
 	}
 
 	public void removeSecrets(ContactId c) {
 		synchLock.lock();
 		try {
-			for(TransportTagRecogniser r : recognisers.values())
+			for (TransportTagRecogniser r : recognisers.values())
 				r.removeSecrets(c);
 		} finally {
 			synchLock.unlock();
@@ -95,7 +95,7 @@ class TagRecogniserImpl implements TagRecogniser {
 	public void removeSecrets() {
 		synchLock.lock();
 		try {
-			for(TransportTagRecogniser r : recognisers.values())
+			for (TransportTagRecogniser r : recognisers.values())
 				r.removeSecrets();
 		} finally {
 			synchLock.unlock();
diff --git a/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java
index 0898120440..9d0d4e0429 100644
--- a/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java
+++ b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java
@@ -48,13 +48,13 @@ class TransportTagRecogniser {
 		synchLock.lock();
 		try {
 			TagContext t = tagMap.remove(new Bytes(tag));
-			if(t == null) return null; // The tag was not expected
+			if (t == null) return null; // The tag was not expected
 			// Update the reordering window and the expected tags
 			SecretKey key = crypto.deriveTagKey(t.secret, !t.alice);
-			for(long streamNumber : t.window.setSeen(t.streamNumber)) {
+			for (long streamNumber : t.window.setSeen(t.streamNumber)) {
 				byte[] tag1 = new byte[TAG_LENGTH];
 				crypto.encodeTag(tag1, key, streamNumber);
-				if(streamNumber < t.streamNumber) {
+				if (streamNumber < t.streamNumber) {
 					TagContext removed = tagMap.remove(new Bytes(tag1));
 					assert removed != null;
 				} else {
@@ -85,7 +85,7 @@ class TransportTagRecogniser {
 			// Create the reordering window and the expected tags
 			SecretKey key = crypto.deriveTagKey(secret, !alice);
 			ReorderingWindow window = new ReorderingWindow(centre, bitmap);
-			for(long streamNumber : window.getUnseen()) {
+			for (long streamNumber : window.getUnseen()) {
 				byte[] tag = new byte[TAG_LENGTH];
 				crypto.encodeTag(tag, key, streamNumber);
 				TagContext added = new TagContext(contactId, alice, period,
@@ -106,7 +106,7 @@ class TransportTagRecogniser {
 		try {
 			RemovalKey k = new RemovalKey(contactId, period);
 			RemovalContext removed = removalMap.remove(k);
-			if(removed == null) throw new IllegalArgumentException();
+			if (removed == null) throw new IllegalArgumentException();
 			removeSecret(removed);
 		} finally {
 			synchLock.unlock();
@@ -118,7 +118,7 @@ class TransportTagRecogniser {
 		// Remove the expected tags
 		SecretKey key = crypto.deriveTagKey(r.secret, !r.alice);
 		byte[] tag = new byte[TAG_LENGTH];
-		for(long streamNumber : r.window.getUnseen()) {
+		for (long streamNumber : r.window.getUnseen()) {
 			crypto.encodeTag(tag, key, streamNumber);
 			TagContext removed = tagMap.remove(new Bytes(tag));
 			assert removed != null;
@@ -129,9 +129,9 @@ class TransportTagRecogniser {
 		synchLock.lock();
 		try {
 			Collection<RemovalKey> keysToRemove = new ArrayList<RemovalKey>();
-			for(RemovalKey k : removalMap.keySet())
-				if(k.contactId.equals(c)) keysToRemove.add(k);
-			for(RemovalKey k : keysToRemove)
+			for (RemovalKey k : removalMap.keySet())
+				if (k.contactId.equals(c)) keysToRemove.add(k);
+			for (RemovalKey k : keysToRemove)
 				removeSecret(k.contactId, k.period);
 		} finally {
 			synchLock.unlock();
@@ -141,7 +141,7 @@ class TransportTagRecogniser {
 	void removeSecrets() {
 		synchLock.lock();
 		try {
-			for(RemovalContext r : removalMap.values()) removeSecret(r);
+			for (RemovalContext r : removalMap.values()) removeSecret(r);
 			assert tagMap.isEmpty();
 			removalMap.clear();
 		} finally {
@@ -191,7 +191,7 @@ class TransportTagRecogniser {
 
 		@Override
 		public boolean equals(Object o) {
-			if(o instanceof RemovalKey) {
+			if (o instanceof RemovalKey) {
 				RemovalKey k = (RemovalKey) o;
 				return contactId.equals(k.contactId) && period == k.period;
 			}
diff --git a/briar-core/src/org/briarproject/util/ByteUtils.java b/briar-core/src/org/briarproject/util/ByteUtils.java
index 9cc9e6bc88..777d823189 100644
--- a/briar-core/src/org/briarproject/util/ByteUtils.java
+++ b/briar-core/src/org/briarproject/util/ByteUtils.java
@@ -13,24 +13,24 @@ public class ByteUtils {
 	public static final long MAX_32_BIT_UNSIGNED = 4294967295L; // 2^32 - 1
 
 	public static void writeUint8(int i, byte[] b, int offset) {
-		if(i < 0) throw new IllegalArgumentException();
-		if(i > 255) throw new IllegalArgumentException();
-		if(b.length < offset) throw new IllegalArgumentException();
+		if (i < 0) throw new IllegalArgumentException();
+		if (i > 255) throw new IllegalArgumentException();
+		if (b.length < offset) throw new IllegalArgumentException();
 		b[offset] = (byte) i;
 	}
 
 	public static void writeUint16(int i, byte[] b, int offset) {
-		if(i < 0) throw new IllegalArgumentException();
-		if(i > MAX_16_BIT_UNSIGNED) throw new IllegalArgumentException();
-		if(b.length < offset + 2) throw new IllegalArgumentException();
+		if (i < 0) throw new IllegalArgumentException();
+		if (i > MAX_16_BIT_UNSIGNED) throw new IllegalArgumentException();
+		if (b.length < offset + 2) throw new IllegalArgumentException();
 		b[offset] = (byte) (i >> 8);
 		b[offset + 1] = (byte) (i & 0xFF);
 	}
 
 	public static void writeUint32(long i, byte[] b, int offset) {
-		if(i < 0) throw new IllegalArgumentException();
-		if(i > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException();
-		if(b.length < offset + 4) throw new IllegalArgumentException();
+		if (i < 0) throw new IllegalArgumentException();
+		if (i > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException();
+		if (b.length < offset + 4) throw new IllegalArgumentException();
 		b[offset] = (byte) (i >> 24);
 		b[offset + 1] = (byte) (i >> 16 & 0xFF);
 		b[offset + 2] = (byte) (i >> 8 & 0xFF);
@@ -38,21 +38,21 @@ public class ByteUtils {
 	}
 
 	public static int readUint16(byte[] b, int offset) {
-		if(b.length < offset + 2) throw new IllegalArgumentException();
+		if (b.length < offset + 2) throw new IllegalArgumentException();
 		return ((b[offset] & 0xFF) << 8) | (b[offset + 1] & 0xFF);
 	}
 
 	public static long readUint32(byte[] b, int offset) {
-		if(b.length < offset + 4) throw new IllegalArgumentException();
+		if (b.length < offset + 4) throw new IllegalArgumentException();
 		return ((b[offset] & 0xFFL) << 24) | ((b[offset + 1] & 0xFFL) << 16)
 				| ((b[offset + 2] & 0xFFL) << 8) | (b[offset + 3] & 0xFFL);
 	}
 
 	public static int readUint(byte[] b, int bits) {
-		if(b.length << 3 < bits) throw new IllegalArgumentException();
+		if (b.length << 3 < bits) throw new IllegalArgumentException();
 		int result = 0;
-		for(int i = 0; i < bits; i++) {
-			if((b[i >> 3] & 128 >> (i & 7)) != 0) result |= 1 << bits - i - 1;
+		for (int i = 0; i < bits; i++) {
+			if ((b[i >> 3] & 128 >> (i & 7)) != 0) result |= 1 << bits - i - 1;
 		}
 		assert result >= 0;
 		assert result < 1 << bits;
diff --git a/briar-core/src/org/briarproject/util/LatchedReference.java b/briar-core/src/org/briarproject/util/LatchedReference.java
index c9f35b687c..43763bfa79 100644
--- a/briar-core/src/org/briarproject/util/LatchedReference.java
+++ b/briar-core/src/org/briarproject/util/LatchedReference.java
@@ -15,8 +15,8 @@ public class LatchedReference<T> {
 	}
 
 	public boolean set(T t) {
-		if(t == null) throw new IllegalArgumentException();
-		if(reference.compareAndSet(null, t)) {
+		if (t == null) throw new IllegalArgumentException();
+		if (reference.compareAndSet(null, t)) {
 			latch.countDown();
 			return true;
 		}
diff --git a/briar-core/src/org/briarproject/util/OsUtils.java b/briar-core/src/org/briarproject/util/OsUtils.java
index a9838a30eb..547db92e1a 100644
--- a/briar-core/src/org/briarproject/util/OsUtils.java
+++ b/briar-core/src/org/briarproject/util/OsUtils.java
@@ -15,14 +15,14 @@ public class OsUtils {
 	}
 
 	public static boolean isMacLeopardOrNewer() {
-		if(!isMac() || version == null) return false;
+		if (!isMac() || version == null) return false;
 		try {
 			String[] v = version.split("\\.");
-			if(v.length != 3) return false;
+			if (v.length != 3) return false;
 			int major = Integer.parseInt(v[0]);
 			int minor = Integer.parseInt(v[1]);
 			return major >= 10 && minor >= 5;
-		} catch(NumberFormatException e) {
+		} catch (NumberFormatException e) {
 			return false;
 		}
 	}
diff --git a/briar-core/src/org/briarproject/util/StringUtils.java b/briar-core/src/org/briarproject/util/StringUtils.java
index c8dd0e1513..0f62c62a8f 100644
--- a/briar-core/src/org/briarproject/util/StringUtils.java
+++ b/briar-core/src/org/briarproject/util/StringUtils.java
@@ -16,8 +16,8 @@ public class StringUtils {
 
 	public static String join(Collection<String> strings, String separator) {
 		StringBuilder joined = new StringBuilder();
-		for(String s : strings) {
-			if(joined.length() > 0) joined.append(separator);
+		for (String s : strings) {
+			if (joined.length() > 0) joined.append(separator);
 			joined.append(s);
 		}
 		return joined.toString();
@@ -26,7 +26,7 @@ public class StringUtils {
 	public static byte[] toUtf8(String s) {
 		try {
 			return s.getBytes("UTF-8");
-		} catch(UnsupportedEncodingException e) {
+		} catch (UnsupportedEncodingException e) {
 			throw new RuntimeException(e);
 		}
 	}
@@ -34,7 +34,7 @@ public class StringUtils {
 	public static String fromUtf8(byte[] bytes) {
 		try {
 			return new String(bytes, "UTF-8");
-		} catch(UnsupportedEncodingException e) {
+		} catch (UnsupportedEncodingException e) {
 			throw new RuntimeException(e);
 		}
 	}
@@ -42,7 +42,7 @@ public class StringUtils {
 	/** Converts the given byte array to a hex character array. */
 	public static char[] toHexChars(byte[] bytes) {
 		char[] hex = new char[bytes.length * 2];
-		for(int i = 0, j = 0; i < bytes.length; i++) {
+		for (int i = 0, j = 0; i < bytes.length; i++) {
 			hex[j++] = HEX[(bytes[i] >> 4) & 0xF];
 			hex[j++] = HEX[bytes[i] & 0xF];
 		}
@@ -57,9 +57,9 @@ public class StringUtils {
 	/** Converts the given hex string to a byte array. */
 	public static byte[] fromHexString(String hex) {
 		int len = hex.length();
-		if(len % 2 != 0) throw new IllegalArgumentException("Not a hex string");
+		if (len % 2 != 0) throw new IllegalArgumentException("Not a hex string");
 		byte[] bytes = new byte[len / 2];
-		for(int i = 0, j = 0; i < len; i += 2, j++) {
+		for (int i = 0, j = 0; i < len; i += 2, j++) {
 			int high = hexDigitToInt(hex.charAt(i));
 			int low = hexDigitToInt(hex.charAt(i + 1));
 			bytes[j] = (byte) ((high << 4) + low);
@@ -68,9 +68,9 @@ public class StringUtils {
 	}
 
 	private static int hexDigitToInt(char c) {
-		if(c >= '0' && c <= '9') return c - '0';
-		if(c >= 'A' && c <= 'F') return c - 'A' + 10;
-		if(c >= 'a' && c <= 'f') return c - 'a' + 10;
+		if (c >= '0' && c <= '9') return c - '0';
+		if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+		if (c >= 'a' && c <= 'f') return c - 'a' + 10;
 		throw new IllegalArgumentException("Not a hex digit: " + c);
 	}
 }
diff --git a/briar-desktop/src/org/briarproject/lifecycle/DesktopLifecycleModule.java b/briar-desktop/src/org/briarproject/lifecycle/DesktopLifecycleModule.java
index ea12c70987..bf1a41d2a9 100644
--- a/briar-desktop/src/org/briarproject/lifecycle/DesktopLifecycleModule.java
+++ b/briar-desktop/src/org/briarproject/lifecycle/DesktopLifecycleModule.java
@@ -12,7 +12,7 @@ public class DesktopLifecycleModule extends LifecycleModule {
 	protected void configure() {
 		bind(LifecycleManager.class).to(
 				LifecycleManagerImpl.class).in(Singleton.class);
-		if(OsUtils.isWindows()) {
+		if (OsUtils.isWindows()) {
 			bind(ShutdownManager.class).to(
 					WindowsShutdownManagerImpl.class).in(Singleton.class);
 		} else {
diff --git a/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java b/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java
index 3585e557f2..ef3343c07d 100644
--- a/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java
+++ b/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java
@@ -54,7 +54,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
 	public int addShutdownHook(Runnable r) {
 		synchLock.lock();
 		try {
-			if(!initialised) initialise();
+			if (!initialised) initialise();
 			return super.addShutdownHook(r);
 		} finally {
 			synchLock.unlock();
@@ -68,7 +68,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
 
 	// Locking: synchLock
 	private void initialise() {
-		if(OsUtils.isWindows()) {
+		if (OsUtils.isWindows()) {
 			new EventLoop().start();
 		} else {
 			LOG.warning("Windows shutdown manager used on non-Windows OS");
@@ -82,17 +82,17 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
 		try {
 			boolean interrupted = false;
 			// Start each hook in its own thread
-			for(Thread hook : hooks.values()) hook.start();
+			for (Thread hook : hooks.values()) hook.start();
 			// Wait for all the hooks to finish
-			for(Thread hook : hooks.values()) {
+			for (Thread hook : hooks.values()) {
 				try {
 					hook.join();
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.warning("Interrupted while running shutdown hooks");
 					interrupted = true;
 				}
 			}
-			if(interrupted) Thread.currentThread().interrupt();
+			if (interrupted) Thread.currentThread().interrupt();
 		} finally {
 			synchLock.unlock();
 		}
@@ -114,7 +114,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
 				WindowProc proc = new WindowProc() {
 					public LRESULT callback(HWND hwnd, int msg, WPARAM wp,
 							LPARAM lp) {
-						if(msg == WM_QUERYENDSESSION) {
+						if (msg == WM_QUERYENDSESSION) {
 							// It's safe to delay returning from this message
 							runShutdownHooks();
 						}
@@ -130,19 +130,19 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
 					// Use SetWindowLongPtr if available (64-bit safe)
 					user32.SetWindowLongPtr(hwnd, GWL_WNDPROC, proc);
 					LOG.info("Registered 64-bit callback");
-				} catch(UnsatisfiedLinkError e) {
+				} catch (UnsatisfiedLinkError e) {
 					// Use SetWindowLong if SetWindowLongPtr isn't available
 					user32.SetWindowLong(hwnd, GWL_WNDPROC, proc);
 					LOG.info("Registered 32-bit callback");
 				}
 				// Handle events until the window is destroyed
 				MSG msg = new MSG();
-				while(user32.GetMessage(msg, null, 0, 0) > 0) {
+				while (user32.GetMessage(msg, null, 0, 0) > 0) {
 					user32.TranslateMessage(msg);
 					user32.DispatchMessage(msg);
 				}
-			} catch(UnsatisfiedLinkError e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (UnsatisfiedLinkError e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
@@ -158,7 +158,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
 		@Override
 		public void start() {
 			// Ensure the thread is only started once
-			if(!called.getAndSet(true)) super.start();
+			if (!called.getAndSet(true)) super.start();
 		}
 	}
 
diff --git a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java
index 45dca315f2..3db1dfebfa 100644
--- a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java
+++ b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java
@@ -81,13 +81,13 @@ class BluetoothPlugin implements DuplexPlugin {
 		// Initialise the Bluetooth stack
 		try {
 			localDevice = LocalDevice.getLocalDevice();
-		} catch(UnsatisfiedLinkError e) {
+		} catch (UnsatisfiedLinkError e) {
 			// On Linux the user may need to install libbluetooth-dev
-			if(OsUtils.isLinux())
+			if (OsUtils.isLinux())
 				callback.showMessage("BLUETOOTH_INSTALL_LIBS");
 			return false;
 		}
-		if(LOG.isLoggable(INFO))
+		if (LOG.isLoggable(INFO))
 			LOG.info("Local address " + localDevice.getBluetoothAddress());
 		running = true;
 		bind();
@@ -97,7 +97,7 @@ class BluetoothPlugin implements DuplexPlugin {
 	private void bind() {
 		ioExecutor.execute(new Runnable() {
 			public void run() {
-				if(!running) return;
+				if (!running) return;
 				// Advertise the Bluetooth address to contacts
 				TransportProperties p = new TransportProperties();
 				p.put("address", localDevice.getBluetoothAddress());
@@ -107,12 +107,12 @@ class BluetoothPlugin implements DuplexPlugin {
 				StreamConnectionNotifier ss;
 				try {
 					ss = (StreamConnectionNotifier) Connector.open(url);
-				} catch(IOException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (IOException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					return;
 				}
-				if(!running) {
+				if (!running) {
 					tryToClose(ss);
 					return;
 				}
@@ -129,7 +129,7 @@ class BluetoothPlugin implements DuplexPlugin {
 
 	private String getUuid() {
 		String uuid = callback.getLocalProperties().get("uuid");
-		if(uuid == null) {
+		if (uuid == null) {
 			byte[] random = new byte[UUID_BYTES];
 			secureRandom.nextBytes(random);
 			uuid = UUID.nameUUIDFromBytes(random).toString();
@@ -142,24 +142,24 @@ class BluetoothPlugin implements DuplexPlugin {
 
 	private void tryToClose(StreamConnectionNotifier ss) {
 		try {
-			if(ss != null) ss.close();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (ss != null) ss.close();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	private void acceptContactConnections(StreamConnectionNotifier ss) {
-		while(true) {
+		while (true) {
 			StreamConnection s;
 			try {
 				s = ss.acceptAndOpen();
-			} catch(IOException e) {
+			} catch (IOException e) {
 				// This is expected when the socket is closed
-				if(LOG.isLoggable(INFO)) LOG.info(e.toString());
+				if (LOG.isLoggable(INFO)) LOG.info(e.toString());
 				return;
 			}
 			callback.incomingConnectionCreated(wrapSocket(s));
-			if(!running) return;
+			if (!running) return;
 		}
 	}
 
@@ -185,22 +185,22 @@ class BluetoothPlugin implements DuplexPlugin {
 	}
 
 	public void poll(final Collection<ContactId> connected) {
-		if(!running) return;
+		if (!running) return;
 		// Try to connect to known devices in parallel
 		Map<ContactId, TransportProperties> remote =
 				callback.getRemoteProperties();
-		for(Entry<ContactId, TransportProperties> e : remote.entrySet()) {
+		for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
 			final ContactId c = e.getKey();
-			if(connected.contains(c)) continue;
+			if (connected.contains(c)) continue;
 			final String address = e.getValue().get("address");
-			if(StringUtils.isNullOrEmpty(address)) continue;
+			if (StringUtils.isNullOrEmpty(address)) continue;
 			final String uuid = e.getValue().get("uuid");
-			if(StringUtils.isNullOrEmpty(uuid)) continue;
+			if (StringUtils.isNullOrEmpty(uuid)) continue;
 			ioExecutor.execute(new Runnable() {
 				public void run() {
-					if(!running) return;
+					if (!running) return;
 					StreamConnection s = connect(makeUrl(address, uuid));
-					if(s != null)
+					if (s != null)
 						callback.outgoingConnectionCreated(c, wrapSocket(s));
 				}
 			});
@@ -208,28 +208,28 @@ class BluetoothPlugin implements DuplexPlugin {
 	}
 
 	private StreamConnection connect(String url) {
-		if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + url);
+		if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + url);
 		try {
 			StreamConnection s = (StreamConnection) Connector.open(url);
-			if(LOG.isLoggable(INFO)) LOG.info("Connected to " + url);
+			if (LOG.isLoggable(INFO)) LOG.info("Connected to " + url);
 			return s;
-		} catch(IOException e) {
-			if(LOG.isLoggable(INFO)) LOG.info("Could not connect to " + url);
+		} catch (IOException e) {
+			if (LOG.isLoggable(INFO)) LOG.info("Could not connect to " + url);
 			return null;
 		}
 	}
 
 	public DuplexTransportConnection createConnection(ContactId c) {
-		if(!running) return null;
+		if (!running) return null;
 		TransportProperties p = callback.getRemoteProperties().get(c);
-		if(p == null) return null;
+		if (p == null) return null;
 		String address = p.get("address");
-		if(StringUtils.isNullOrEmpty(address)) return null;
+		if (StringUtils.isNullOrEmpty(address)) return null;
 		String uuid = p.get("uuid");
-		if(StringUtils.isNullOrEmpty(uuid)) return null;
+		if (StringUtils.isNullOrEmpty(uuid)) return null;
 		String url = makeUrl(address, uuid);
 		StreamConnection s = connect(url);
-		if(s == null) return null;
+		if (s == null) return null;
 		return new BluetoothTransportConnection(this, s);
 	}
 
@@ -239,7 +239,7 @@ class BluetoothPlugin implements DuplexPlugin {
 
 	public DuplexTransportConnection createInvitationConnection(PseudoRandom r,
 			long timeout) {
-		if(!running) return null;
+		if (!running) return null;
 		// Use the invitation codes to generate the UUID
 		byte[] b = r.nextBytes(UUID_BYTES);
 		String uuid = UUID.nameUUIDFromBytes(b).toString();
@@ -250,11 +250,11 @@ class BluetoothPlugin implements DuplexPlugin {
 		final StreamConnectionNotifier ss;
 		try {
 			ss = (StreamConnectionNotifier) Connector.open(url);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			return null;
 		}
-		if(!running) {
+		if (!running) {
 			tryToClose(ss);
 			return null;
 		}
@@ -266,8 +266,8 @@ class BluetoothPlugin implements DuplexPlugin {
 		// Wait for an incoming or outgoing connection
 		try {
 			StreamConnection s = socketLatch.waitForReference(timeout);
-			if(s != null) return new BluetoothTransportConnection(this, s);
-		} catch(InterruptedException e) {
+			if (s != null) return new BluetoothTransportConnection(this, s);
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while exchanging invitations");
 			Thread.currentThread().interrupt();
 		} finally {
@@ -281,8 +281,8 @@ class BluetoothPlugin implements DuplexPlugin {
 		// Try to make the device discoverable (requires root on Linux)
 		try {
 			localDevice.setDiscoverable(GIAC);
-		} catch(BluetoothStateException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (BluetoothStateException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
@@ -304,8 +304,8 @@ class BluetoothPlugin implements DuplexPlugin {
 			DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent();
 			long now = clock.currentTimeMillis();
 			long end = now + timeout;
-			while(now < end && running && !socketLatch.isSet()) {
-				if(!discoverySemaphore.tryAcquire()) {
+			while (now < end && running && !socketLatch.isSet()) {
+				if (!discoverySemaphore.tryAcquire()) {
 					LOG.info("Another device discovery is in progress");
 					return;
 				}
@@ -314,20 +314,20 @@ class BluetoothPlugin implements DuplexPlugin {
 							new InvitationListener(discoveryAgent, uuid);
 					discoveryAgent.startInquiry(GIAC, listener);
 					String url = listener.waitForUrl();
-					if(url == null) continue;
+					if (url == null) continue;
 					StreamConnection s = connect(url);
-					if(s == null) continue;
+					if (s == null) continue;
 					LOG.info("Outgoing connection");
-					if(!socketLatch.set(s)) {
+					if (!socketLatch.set(s)) {
 						LOG.info("Closing redundant connection");
 						tryToClose(s);
 					}
 					return;
-				} catch(BluetoothStateException e) {
-					if(LOG.isLoggable(WARNING))
+				} catch (BluetoothStateException e) {
+					if (LOG.isLoggable(WARNING))
 						LOG.log(WARNING, e.toString(), e);
 					return;
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					LOG.warning("Interrupted while waiting for URL");
 					Thread.currentThread().interrupt();
 					return;
@@ -339,9 +339,9 @@ class BluetoothPlugin implements DuplexPlugin {
 
 		private void tryToClose(StreamConnection s) {
 			try {
-				if(s != null) s.close();
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+				if (s != null) s.close();
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
@@ -365,13 +365,13 @@ class BluetoothPlugin implements DuplexPlugin {
 			try {
 				StreamConnection s = serverSocket.acceptAndOpen();
 				LOG.info("Incoming connection");
-				if(!socketLatch.set(s)) {
+				if (!socketLatch.set(s)) {
 					LOG.info("Closing redundant connection");
 					s.close();
 				}
-			} catch(IOException e) {
+			} catch (IOException e) {
 				// This is expected when the socket is closed
-				if(LOG.isLoggable(INFO)) LOG.info(e.toString());
+				if (LOG.isLoggable(INFO)) LOG.info(e.toString());
 			}
 		}
 	}
diff --git a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java
index 8e70db480b..8f852f1ef8 100644
--- a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java
+++ b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java
@@ -49,8 +49,8 @@ class BluetoothTransportConnection implements DuplexTransportConnection {
 
 		public void dispose(boolean exception, boolean recognised)
 				throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) stream.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) stream.close();
 		}
 	}
 
@@ -73,8 +73,8 @@ class BluetoothTransportConnection implements DuplexTransportConnection {
 		}
 
 		public void dispose(boolean exception) throws IOException {
-			if(halfClosed.getAndSet(true) || exception)
-				if(!closed.getAndSet(true)) stream.close();
+			if (halfClosed.getAndSet(true) || exception)
+				if (!closed.getAndSet(true)) stream.close();
 		}
 	}
 }
diff --git a/briar-desktop/src/org/briarproject/plugins/bluetooth/InvitationListener.java b/briar-desktop/src/org/briarproject/plugins/bluetooth/InvitationListener.java
index a80d2e7698..38d9ce3c61 100644
--- a/briar-desktop/src/org/briarproject/plugins/bluetooth/InvitationListener.java
+++ b/briar-desktop/src/org/briarproject/plugins/bluetooth/InvitationListener.java
@@ -47,22 +47,22 @@ class InvitationListener implements DiscoveryListener {
 		try {
 			discoveryAgent.searchServices(null, uuids, device, this);
 			searches.incrementAndGet();
-		} catch(BluetoothStateException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (BluetoothStateException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
 	public void servicesDiscovered(int transaction, ServiceRecord[] services) {
-		for(ServiceRecord record : services) {
+		for (ServiceRecord record : services) {
 			// Does this service have a URL?
 			String serviceUrl = record.getConnectionURL(
 					ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
-			if(serviceUrl == null) continue;
+			if (serviceUrl == null) continue;
 			// Does this service have the UUID we're looking for?
 			Collection<String> uuids = new TreeSet<String>();
 			findNestedClassIds(record.getAttributeValue(0x1), uuids);
-			for(String u : uuids) {
-				if(uuid.equalsIgnoreCase(u)) {
+			for (String u : uuids) {
+				if (uuid.equalsIgnoreCase(u)) {
 					// The UUID matches - store the URL
 					url = serviceUrl;
 					finished.countDown();
@@ -73,30 +73,30 @@ class InvitationListener implements DiscoveryListener {
 	}
 
 	public void inquiryCompleted(int discoveryType) {
-		if(searches.decrementAndGet() == 0) finished.countDown();
+		if (searches.decrementAndGet() == 0) finished.countDown();
 	}
 
 	public void serviceSearchCompleted(int transaction, int response) {
-		if(searches.decrementAndGet() == 0) finished.countDown();
+		if (searches.decrementAndGet() == 0) finished.countDown();
 	}
 
 	// UUIDs are sometimes buried in nested data elements
 	private void findNestedClassIds(Object o, Collection<String> ids) {
 		o = getDataElementValue(o);
-		if(o instanceof Enumeration<?>) {
-			for(Object o1 : Collections.list((Enumeration<?>) o))
+		if (o instanceof Enumeration<?>) {
+			for (Object o1 : Collections.list((Enumeration<?>) o))
 				findNestedClassIds(o1, ids);
-		} else if(o instanceof UUID) {
+		} else if (o instanceof UUID) {
 			ids.add(o.toString());
 		}
 	}
 
 	private Object getDataElementValue(Object o) {
-		if(o instanceof DataElement) {
+		if (o instanceof DataElement) {
 			// Bluecove throws an exception if the type is unknown
 			try {
 				return ((DataElement) o).getValue();
-			} catch(ClassCastException e) {
+			} catch (ClassCastException e) {
 				return null;
 			}
 		}
diff --git a/briar-desktop/src/org/briarproject/plugins/file/PollingRemovableDriveMonitor.java b/briar-desktop/src/org/briarproject/plugins/file/PollingRemovableDriveMonitor.java
index c86b657d7e..a09508582f 100644
--- a/briar-desktop/src/org/briarproject/plugins/file/PollingRemovableDriveMonitor.java
+++ b/briar-desktop/src/org/briarproject/plugins/file/PollingRemovableDriveMonitor.java
@@ -53,24 +53,24 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
 	public void run() {
 		try {
 			Collection<File> drives = finder.findRemovableDrives();
-			while(running) {
+			while (running) {
 				pollingLock.lock();
 				try {
 					stopPolling.await(pollingInterval, MILLISECONDS);
 				} finally {
 					pollingLock.unlock();
 				}
-				if(!running) return;
+				if (!running) return;
 				Collection<File> newDrives = finder.findRemovableDrives();
-				for(File f : newDrives) {
-					if(!drives.contains(f)) callback.driveInserted(f);
+				for (File f : newDrives) {
+					if (!drives.contains(f)) callback.driveInserted(f);
 				}
 				drives = newDrives;
 			}
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			LOG.warning("Interrupted while waiting to poll");
 			Thread.currentThread().interrupt();
-		} catch(IOException e) {
+		} catch (IOException e) {
 			callback.exceptionThrown(e);
 		}
 	}
diff --git a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java
index f648ff092c..1a620ce1bd 100644
--- a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java
+++ b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java
@@ -67,16 +67,16 @@ implements RemovableDriveMonitor.Callback {
 		try {
 			List<File> drives =
 					new ArrayList<File>(finder.findRemovableDrives());
-			if(drives.isEmpty()) return null;
+			if (drives.isEmpty()) return null;
 			String[] paths = new String[drives.size()];
-			for(int i = 0; i < paths.length; i++) {
+			for (int i = 0; i < paths.length; i++) {
 				paths[i] = drives.get(i).getPath();
 			}
 			int i = callback.showChoice(paths, "REMOVABLE_DRIVE_CHOOSE_DRIVE");
-			if(i == -1) return null;
+			if (i == -1) return null;
 			return drives.get(i);
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			return null;
 		}
 	}
@@ -95,29 +95,29 @@ implements RemovableDriveMonitor.Callback {
 	protected Collection<File> findFilesByName(String filename) {
 		List<File> matches = new ArrayList<File>();
 		try {
-			for(File drive : finder.findRemovableDrives()) {
+			for (File drive : finder.findRemovableDrives()) {
 				File[] files = drive.listFiles();
-				if(files != null) {
-					for(File f : files) {
-						if(f.isFile() && filename.equals(f.getName()))
+				if (files != null) {
+					for (File f : files) {
+						if (f.isFile() && filename.equals(f.getName()))
 							matches.add(f);
 					}
 				}
 			}
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 		return Collections.unmodifiableList(matches);
 	}
 
 	public void driveInserted(File root) {
 		File[] files = root.listFiles();
-		if(files != null) {
-			for(File f : files) if(f.isFile()) createReaderFromFile(f);
+		if (files != null) {
+			for (File f : files) if (f.isFile()) createReaderFromFile(f);
 		}
 	}
 
 	public void exceptionThrown(IOException e) {
-		if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 	}
 }
diff --git a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java
index 68b1eaf31c..cc817061d2 100644
--- a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java
+++ b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java
@@ -31,18 +31,18 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
 	public SimplexPlugin createPlugin(SimplexPluginCallback callback) {
 		RemovableDriveFinder finder;
 		RemovableDriveMonitor monitor;
-		if(OsUtils.isLinux()) {
+		if (OsUtils.isLinux()) {
 			finder = new LinuxRemovableDriveFinder();
 			monitor = new LinuxRemovableDriveMonitor();
-		} else if(OsUtils.isMacLeopardOrNewer()) {
+		} else if (OsUtils.isMacLeopardOrNewer()) {
 			finder = new MacRemovableDriveFinder();
 			monitor = new MacRemovableDriveMonitor();
-		} else if(OsUtils.isMac()) {
+		} else if (OsUtils.isMac()) {
 			// JNotify requires OS X 10.5 or newer, so we have to poll
 			finder = new MacRemovableDriveFinder();
 			monitor = new PollingRemovableDriveMonitor(ioExecutor, finder,
 					POLLING_INTERVAL);
-		} else if(OsUtils.isWindows()) {
+		} else if (OsUtils.isWindows()) {
 			finder = new WindowsRemovableDriveFinder();
 			monitor = new PollingRemovableDriveMonitor(ioExecutor, finder,
 					POLLING_INTERVAL);
diff --git a/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java b/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java
index 270a1354f0..d5c2d76fe4 100644
--- a/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java
+++ b/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java
@@ -18,17 +18,17 @@ abstract class UnixRemovableDriveFinder implements RemovableDriveFinder {
 		Process p = new ProcessBuilder(getMountCommand()).start();
 		Scanner s = new Scanner(p.getInputStream(), "UTF-8");
 		try {
-			while(s.hasNextLine()) {
+			while (s.hasNextLine()) {
 				String line = s.nextLine();
 				String[] tokens = line.split(" ");
-				if(tokens.length < 3) continue;
+				if (tokens.length < 3) continue;
 				// The general format is "/dev/foo on /bar/baz ..."
-				if(tokens[0].startsWith("/dev/") && tokens[1].equals("on")) {
+				if (tokens[0].startsWith("/dev/") && tokens[1].equals("on")) {
 					// The path may contain spaces so we can't use tokens[2]
 					String path = parseMountPoint(line);
-					if(isRemovableDriveMountPoint(path)) {
+					if (isRemovableDriveMountPoint(path)) {
 						File f = new File(path);
-						if(f.exists() && f.isDirectory()) drives.add(f);
+						if (f.exists() && f.isDirectory()) drives.add(f);
 					}
 				}
 			}
diff --git a/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveMonitor.java b/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveMonitor.java
index bc2ca3fd9f..de0d04d9cf 100644
--- a/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveMonitor.java
+++ b/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveMonitor.java
@@ -33,9 +33,9 @@ JNotifyListener {
 		try {
 			Class.forName("net.contentobjects.jnotify.JNotify");
 			return null;
-		} catch(UnsatisfiedLinkError e) {
+		} catch (UnsatisfiedLinkError e) {
 			return e;
-		} catch(ClassNotFoundException e) {
+		} catch (ClassNotFoundException e) {
 			return e;
 		}
 	}
@@ -43,11 +43,11 @@ JNotifyListener {
 	public static void checkEnabled() throws IOException {
 		staticSynchLock.lock();
 		try {
-			if(!triedLoad) {
+			if (!triedLoad) {
 				loadError = tryLoad();
 				triedLoad = true;
 			}
-			if(loadError != null) throw new IOException(loadError.toString());
+			if (loadError != null) throw new IOException(loadError.toString());
 		} finally {
 			staticSynchLock.unlock();
 		}
@@ -57,8 +57,8 @@ JNotifyListener {
 		checkEnabled();
 		List<Integer> watches = new ArrayList<Integer>();
 		int mask = JNotify.FILE_CREATED;
-		for(String path : getPathsToWatch()) {
-			if(new File(path).exists())
+		for (String path : getPathsToWatch()) {
+			if (new File(path).exists())
 				watches.add(JNotify.addWatch(path, mask, false, this));
 		}
 		synchLock.lock();
@@ -87,7 +87,7 @@ JNotifyListener {
 		} finally {
 			synchLock.unlock();
 		}
-		for(Integer w : watches) JNotify.removeWatch(w);
+		for (Integer w : watches) JNotify.removeWatch(w);
 	}
 
 	public void fileCreated(int wd, String rootPath, String name) {
@@ -98,7 +98,7 @@ JNotifyListener {
 		} finally {
 			synchLock.unlock();
 		}
-		if(callback != null)
+		if (callback != null)
 			callback.driveInserted(new File(rootPath + "/" + name));
 	}
 
diff --git a/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java b/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java
index 452d4548b8..cfbb1f5a59 100644
--- a/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java
+++ b/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java
@@ -16,13 +16,13 @@ class WindowsRemovableDriveFinder implements RemovableDriveFinder {
 
 	public Collection<File> findRemovableDrives() throws IOException {
 		File[] roots = File.listRoots();
-		if(roots == null) throw new IOException();
+		if (roots == null) throw new IOException();
 		List<File> drives = new ArrayList<File>();
-		for(File root : roots) {
+		for (File root : roots) {
 			try {
 				int type = Kernel32.INSTANCE.GetDriveType(root.getPath());
-				if(type == DRIVE_REMOVABLE) drives.add(root);
-			} catch(RuntimeException e) {
+				if (type == DRIVE_REMOVABLE) drives.add(root);
+			} catch (RuntimeException e) {
 				throw new IOException(e);
 			}
 		}
diff --git a/briar-desktop/src/org/briarproject/plugins/modem/CountryCodes.java b/briar-desktop/src/org/briarproject/plugins/modem/CountryCodes.java
index b4fb65a00c..0ffb166c83 100644
--- a/briar-desktop/src/org/briarproject/plugins/modem/CountryCodes.java
+++ b/briar-desktop/src/org/briarproject/plugins/modem/CountryCodes.java
@@ -251,23 +251,23 @@ class CountryCodes {
 			new HashMap<String, Country>();
 
 	static {
-		for(Country c : COUNTRIES) COUNTRY_MAP.put(c.iso3166, c);
+		for (Country c : COUNTRIES) COUNTRY_MAP.put(c.iso3166, c);
 	}
 
 	static String translate(String number, String callerIso, String calleeIso) {
 		Country from = COUNTRY_MAP.get(callerIso);
 		Country to = COUNTRY_MAP.get(calleeIso);
-		if(from == null || to == null) return null;
+		if (from == null || to == null) return null;
 		// Strip any prefixes and country codes from the number
 		String plusCountryCode = "+" + to.countryCode;
 		String iddCountryCode = to.idd + to.countryCode;
-		if(number.startsWith(plusCountryCode))
+		if (number.startsWith(plusCountryCode))
 			number = number.substring(plusCountryCode.length());
-		else if(number.startsWith(iddCountryCode))
+		else if (number.startsWith(iddCountryCode))
 			number = number.substring(iddCountryCode.length());
-		else if(number.startsWith(to.ndd))
+		else if (number.startsWith(to.ndd))
 			number = number.substring(to.ndd.length());
-		if(from == to) return from.ndd + number; // National
+		if (from == to) return from.ndd + number; // National
 		return from.idd + to.countryCode + number; // International
 	}
 
diff --git a/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java b/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java
index 2896f48d02..13b628369b 100644
--- a/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java
+++ b/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java
@@ -69,7 +69,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		LOG.info("Starting");
 		try {
 			stateChange.acquire();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while waiting to start");
 		}
@@ -79,13 +79,13 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 			// Find a suitable baud rate and initialise the modem
 			try {
 				boolean foundBaudRate = false;
-				for(int baudRate : BAUD_RATES) {
-					if(port.setParams(baudRate, 8, 1, 0)) {
+				for (int baudRate : BAUD_RATES) {
+					if (port.setParams(baudRate, 8, 1, 0)) {
 						foundBaudRate = true;
 						break;
 					}
 				}
-				if(!foundBaudRate) {
+				if (!foundBaudRate) {
 					tryToClose(port);
 					throw new IOException("No suitable baud rate");
 				}
@@ -93,7 +93,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				port.addEventListener(this);
 				port.writeBytes("ATZ\r\n".getBytes("US-ASCII")); // Reset
 				port.writeBytes("ATE0\r\n".getBytes("US-ASCII")); // Echo off
-			} catch(IOException e) {
+			} catch (IOException e) {
 				tryToClose(port);
 				throw e;
 			}
@@ -104,7 +104,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				try {
 					long now = clock.currentTimeMillis();
 					long end = now + OK_TIMEOUT;
-					while(now < end && !initialised) {
+					while (now < end && !initialised) {
 						initialisedStateChanged.await(end - now, MILLISECONDS);
 						now = clock.currentTimeMillis();
 					}
@@ -112,12 +112,12 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				} finally {
 					synchLock.unlock();
 				}
-			} catch(InterruptedException e) {
+			} catch (InterruptedException e) {
 				tryToClose(port);
 				Thread.currentThread().interrupt();
 				throw new IOException("Interrupted while initialising");
 			}
-			if(success) return true;
+			if (success) return true;
 			tryToClose(port);
 			return false;
 		} finally {
@@ -127,9 +127,9 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 
 	private void tryToClose(SerialPort port) {
 		try {
-			if(port != null) port.closePort();
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (port != null) port.closePort();
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
@@ -148,7 +148,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		// Hang up if necessary and close the port
 		try {
 			stateChange.acquire();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			tryToClose(port);
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while waiting to stop");
@@ -166,7 +166,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		ReliabilityLayer reliability;
 		synchLock.lock();
 		try {
-			if(this.reliability == null) {
+			if (this.reliability == null) {
 				LOG.info("Not hanging up - already on the hook");
 				return;
 			}
@@ -183,18 +183,18 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 			port.writeBytes("+++".getBytes("US-ASCII"));
 			clock.sleep(ESCAPE_SEQUENCE_GUARD_TIME);
 			port.writeBytes("ATH\r\n".getBytes("US-ASCII"));
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			tryToClose(port);
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while hanging up");
-		} catch(IOException e) {
+		} catch (IOException e) {
 			tryToClose(port);
 			throw e;
 		}
 	}
 
 	public boolean dial(String number) throws IOException {
-		if(!stateChange.tryAcquire()) {
+		if (!stateChange.tryAcquire()) {
 			LOG.info("Not dialling - state change in progress");
 			return false;
 		}
@@ -203,11 +203,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 					reliabilityFactory.createReliabilityLayer(this);
 			synchLock.lock();
 			try {
-				if(!initialised) {
+				if (!initialised) {
 					LOG.info("Not dialling - modem not initialised");
 					return false;
 				}
-				if(this.reliability != null) {
+				if (this.reliability != null) {
 					LOG.info("Not dialling - call in progress");
 					return false;
 				}
@@ -220,7 +220,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 			try {
 				String dial = "ATDT" + number + "\r\n";
 				port.writeBytes(dial.getBytes("US-ASCII"));
-			} catch(IOException e) {
+			} catch (IOException e) {
 				tryToClose(port);
 				throw e;
 			}
@@ -230,15 +230,15 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				try {
 					long now = clock.currentTimeMillis();
 					long end = now + CONNECT_TIMEOUT;
-					while(now < end && initialised && !connected) {
+					while (now < end && initialised && !connected) {
 						connectedStateChanged.await(end - now, MILLISECONDS);
 						now = clock.currentTimeMillis();
 					}
-					if(connected) return true;
+					if (connected) return true;
 				} finally {
 					synchLock.unlock();
 				}
-			} catch(InterruptedException e) {
+			} catch (InterruptedException e) {
 				tryToClose(port);
 				Thread.currentThread().interrupt();
 				throw new IOException("Interrupted while dialling");
@@ -258,7 +258,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		} finally {
 			synchLock.unlock();
 		}
-		if(reliability == null) throw new IOException("Not connected");
+		if (reliability == null) throw new IOException("Not connected");
 		return reliability.getInputStream();
 	}
 
@@ -270,14 +270,14 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		} finally {
 			synchLock.unlock();
 		}
-		if(reliability == null) throw new IOException("Not connected");
+		if (reliability == null) throw new IOException("Not connected");
 		return reliability.getOutputStream();
 	}
 
 	public void hangUp() throws IOException {
 		try {
 			stateChange.acquire();
-		} catch(InterruptedException e) {
+		} catch (InterruptedException e) {
 			tryToClose(port);
 			Thread.currentThread().interrupt();
 			throw new IOException("Interrupted while waiting to hang up");
@@ -292,7 +292,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 	public void handleWrite(byte[] b) throws IOException {
 		try {
 			port.writeBytes(b);
-		} catch(IOException e) {
+		} catch (IOException e) {
 			tryToClose(port);
 			throw e;
 		}
@@ -300,20 +300,20 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 
 	public void serialEvent(SerialPortEvent ev) {
 		try {
-			if(ev.isRXCHAR()) {
+			if (ev.isRXCHAR()) {
 				byte[] b = port.readBytes();
-				if(!handleData(b)) handleText(b);
-			} else if(ev.isDSR() && ev.getEventValue() == 0) {
+				if (!handleData(b)) handleText(b);
+			} else if (ev.isDSR() && ev.getEventValue() == 0) {
 				LOG.info("Remote end hung up");
 				hangUp();
 			} else {
-				if(LOG.isLoggable(INFO)) {
+				if (LOG.isLoggable(INFO)) {
 					LOG.info("Serial event " + ev.getEventType() + " " +
 							ev.getEventValue());
 				}
 			}
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
 	}
 
@@ -325,24 +325,24 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		} finally {
 			synchLock.unlock();
 		}
-		if(reliability == null) return false;
+		if (reliability == null) return false;
 		reliability.handleRead(b);
 		return true;
 	}
 
 	private void handleText(byte[] b) throws IOException {
-		if(lineLen + b.length > MAX_LINE_LENGTH) {
+		if (lineLen + b.length > MAX_LINE_LENGTH) {
 			tryToClose(port);
 			throw new IOException("Line too long");
 		}
-		for(int i = 0; i < b.length; i++) {
+		for (int i = 0; i < b.length; i++) {
 			line[lineLen] = b[i];
-			if(b[i] == '\n') {
+			if (b[i] == '\n') {
 				// FIXME: Use CharsetDecoder to catch invalid ASCII
 				String s = new String(line, 0, lineLen, "US-ASCII").trim();
 				lineLen = 0;
-				if(LOG.isLoggable(INFO)) LOG.info("Modem status: " + s);
-				if(s.startsWith("CONNECT")) {
+				if (LOG.isLoggable(INFO)) LOG.info("Modem status: " + s);
+				if (s.startsWith("CONNECT")) {
 					synchLock.lock();
 					try {
 						connected = true;
@@ -352,13 +352,13 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 					}
 					// There might be data in the buffer as well as text
 					int off = i + 1;
-					if(off < b.length) {
+					if (off < b.length) {
 						byte[] data = new byte[b.length - off];
 						System.arraycopy(b, off, data, 0, data.length);
 						handleData(data);
 					}
 					return;
-				} else if(s.equals("BUSY") || s.equals("NO DIALTONE")
+				} else if (s.equals("BUSY") || s.equals("NO DIALTONE")
 						|| s.equals("NO CARRIER")) {
 					synchLock.lock();
 					try {
@@ -367,7 +367,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 					} finally {
 						synchLock.unlock();
 					}
-				} else if(s.equals("OK")) {
+				} else if (s.equals("OK")) {
 					synchLock.lock();
 					try {
 						initialised = true;
@@ -375,13 +375,13 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 					} finally {
 						synchLock.unlock();
 					}
-				} else if(s.equals("RING")) {
+				} else if (s.equals("RING")) {
 					ioExecutor.execute(new Runnable() {
 						public void run() {
 							try {
 								answer();
-							} catch(IOException e) {
-								if(LOG.isLoggable(WARNING))
+							} catch (IOException e) {
+								if (LOG.isLoggable(WARNING))
 									LOG.log(WARNING, e.toString(), e);
 							}
 						}
@@ -394,7 +394,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 	}
 
 	private void answer() throws IOException {
-		if(!stateChange.tryAcquire()) {
+		if (!stateChange.tryAcquire()) {
 			LOG.info("Not answering - state change in progress");
 			return;
 		}
@@ -403,11 +403,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 					reliabilityFactory.createReliabilityLayer(this);
 			synchLock.lock();
 			try {
-				if(!initialised) {
+				if (!initialised) {
 					LOG.info("Not answering - modem not initialised");
 					return;
 				}
-				if(this.reliability != null) {
+				if (this.reliability != null) {
 					LOG.info("Not answering - call in progress");
 					return;
 				}
@@ -419,7 +419,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 			LOG.info("Answering");
 			try {
 				port.writeBytes("ATA\r\n".getBytes("US-ASCII"));
-			} catch(IOException e) {
+			} catch (IOException e) {
 				tryToClose(port);
 				throw e;
 			}
@@ -430,7 +430,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				try {
 					long now = clock.currentTimeMillis();
 					long end = now + CONNECT_TIMEOUT;
-					while(now < end && initialised && !connected) {
+					while (now < end && initialised && !connected) {
 						connectedStateChanged.await(end - now, MILLISECONDS);
 						now = clock.currentTimeMillis();
 					}
@@ -438,12 +438,12 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				} finally {
 					synchLock.unlock();
 				}
-			} catch(InterruptedException e) {
+			} catch (InterruptedException e) {
 				tryToClose(port);
 				Thread.currentThread().interrupt();
 				throw new IOException("Interrupted while answering");
 			}
-			if(success) callback.incomingCallConnected();
+			if (success) callback.incomingCallConnected();
 			else hangUpInner();
 		} finally {
 			stateChange.release();
diff --git a/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java b/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java
index b0a58969cb..48f8b34871 100644
--- a/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java
+++ b/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java
@@ -59,18 +59,18 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
 	}
 
 	public boolean start() {
-		for(String portName : serialPortList.getPortNames()) {
-			if(LOG.isLoggable(INFO))
+		for (String portName : serialPortList.getPortNames()) {
+			if (LOG.isLoggable(INFO))
 				LOG.info("Trying to initialise modem on " + portName);
 			modem = modemFactory.createModem(this, portName);
 			try {
-				if(!modem.start()) continue;
-				if(LOG.isLoggable(INFO))
+				if (!modem.start()) continue;
+				if (LOG.isLoggable(INFO))
 					LOG.info("Initialised modem on " + portName);
 				running = true;
 				return true;
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 		return false;
@@ -78,11 +78,11 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
 
 	public void stop() {
 		running = false;
-		if(modem != null) {
+		if (modem != null) {
 			try {
 				modem.stop();
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 	}
@@ -104,18 +104,18 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
 	}
 
 	boolean resetModem() {
-		if(!running) return false;
-		for(String portName : serialPortList.getPortNames()) {
-			if(LOG.isLoggable(INFO))
+		if (!running) return false;
+		for (String portName : serialPortList.getPortNames()) {
+			if (LOG.isLoggable(INFO))
 				LOG.info("Trying to initialise modem on " + portName);
 			modem = modemFactory.createModem(this, portName);
 			try {
-				if(!modem.start()) continue;
-				if(LOG.isLoggable(INFO))
+				if (!modem.start()) continue;
+				if (LOG.isLoggable(INFO))
 					LOG.info("Initialised modem on " + portName);
 				return true;
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			}
 		}
 		running = false;
@@ -123,26 +123,26 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
 	}
 
 	public DuplexTransportConnection createConnection(ContactId c) {
-		if(!running) return null;
+		if (!running) return null;
 		// Get the ISO 3166 code for the caller's country
 		String fromIso = callback.getLocalProperties().get("iso3166");
-		if(StringUtils.isNullOrEmpty(fromIso)) return null;
+		if (StringUtils.isNullOrEmpty(fromIso)) return null;
 		// Get the ISO 3166 code for the callee's country
 		TransportProperties properties = callback.getRemoteProperties().get(c);
-		if(properties == null) return null;
+		if (properties == null) return null;
 		String toIso = properties.get("iso3166");
-		if(StringUtils.isNullOrEmpty(toIso)) return null;
+		if (StringUtils.isNullOrEmpty(toIso)) return null;
 		// Get the callee's phone number
 		String number = properties.get("number");
-		if(StringUtils.isNullOrEmpty(number)) return null;
+		if (StringUtils.isNullOrEmpty(number)) return null;
 		// Convert the number into direct dialling form
 		number = CountryCodes.translate(number, fromIso, toIso);
-		if(number == null) return null;
+		if (number == null) return null;
 		// Dial the number
 		try {
-			if(!modem.dial(number)) return null;
-		} catch(IOException e) {
-			if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			if (!modem.dial(number)) return null;
+		} catch (IOException e) {
+			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 			resetModem();
 			return null;
 		}
@@ -184,11 +184,11 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
 			LOG.info("Call disconnected");
 			try {
 				modem.hangUp();
-			} catch(IOException e) {
-				if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+			} catch (IOException e) {
+				if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 				exception = true;
 			}
-			if(exception) resetModem();
+			if (exception) resetModem();
 			disposalFinished.countDown();
 		}
 
@@ -203,8 +203,8 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
 			}
 
 			public void dispose(boolean exception, boolean recognised) {
-				if(halfClosed.getAndSet(true) || exception)
-					if(!closed.getAndSet(true)) hangUp(exception);
+				if (halfClosed.getAndSet(true) || exception)
+					if (!closed.getAndSet(true)) hangUp(exception);
 			}
 		}
 
@@ -227,8 +227,8 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
 			}
 
 			public void dispose(boolean exception) {
-				if(halfClosed.getAndSet(true) || exception)
-					if(!closed.getAndSet(true)) hangUp(exception);
+				if (halfClosed.getAndSet(true) || exception)
+					if (!closed.getAndSet(true)) hangUp(exception);
 			}
 		}
 	}
diff --git a/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java b/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java
index f70fc3be71..58b2d75f35 100644
--- a/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java
+++ b/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java
@@ -29,7 +29,7 @@ public class ModemPluginFactory implements DuplexPluginFactory {
 	public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
 		// This plugin is not enabled by default
 		String enabled = callback.getConfig().get("enabled");
-		if(StringUtils.isNullOrEmpty(enabled)) return null;
+		if (StringUtils.isNullOrEmpty(enabled)) return null;
 		return new ModemPlugin(modemFactory, serialPortList, callback,
 				MAX_LATENCY);
 	}
diff --git a/briar-desktop/src/org/briarproject/plugins/modem/SerialPortImpl.java b/briar-desktop/src/org/briarproject/plugins/modem/SerialPortImpl.java
index 1514b01f57..3722e23182 100644
--- a/briar-desktop/src/org/briarproject/plugins/modem/SerialPortImpl.java
+++ b/briar-desktop/src/org/briarproject/plugins/modem/SerialPortImpl.java
@@ -15,16 +15,16 @@ class SerialPortImpl implements SerialPort {
 
 	public void openPort() throws IOException {
 		try {
-			if(!port.openPort()) throw new IOException("Failed to open port");
-		} catch(SerialPortException e) {
+			if (!port.openPort()) throw new IOException("Failed to open port");
+		} catch (SerialPortException e) {
 			throw new IOException(e);
 		}
 	}
 
 	public void closePort() throws IOException {
 		try {
-			if(!port.closePort()) throw new IOException("Failed to close port");
-		} catch(SerialPortException e) {
+			if (!port.closePort()) throw new IOException("Failed to close port");
+		} catch (SerialPortException e) {
 			throw new IOException(e);
 		}
 	}
@@ -33,16 +33,16 @@ class SerialPortImpl implements SerialPort {
 			int parityBits) throws IOException {
 		try {
 			return port.setParams(baudRate, dataBits, stopBits, parityBits);
-		} catch(SerialPortException e) {
+		} catch (SerialPortException e) {
 			throw new IOException(e);
 		}
 	}
 
 	public void purgePort(int flags) throws IOException {
 		try {
-			if(!port.purgePort(flags))
+			if (!port.purgePort(flags))
 				throw new IOException("Failed to purge port");
-		} catch(SerialPortException e) {
+		} catch (SerialPortException e) {
 			throw new IOException(e);
 		}
 	}
@@ -50,7 +50,7 @@ class SerialPortImpl implements SerialPort {
 	public void addEventListener(SerialPortEventListener l) throws IOException {
 		try {
 			port.addEventListener(l);
-		} catch(SerialPortException e) {
+		} catch (SerialPortException e) {
 			throw new IOException(e);
 		}
 	}
@@ -58,15 +58,15 @@ class SerialPortImpl implements SerialPort {
 	public byte[] readBytes() throws IOException {
 		try {
 			return port.readBytes();
-		} catch(SerialPortException e) {
+		} catch (SerialPortException e) {
 			throw new IOException(e);
 		}
 	}
 
 	public void writeBytes(byte[] b) throws IOException {
 		try {
-			if(!port.writeBytes(b)) throw new IOException("Failed to write");
-		} catch(SerialPortException e) {
+			if (!port.writeBytes(b)) throw new IOException("Failed to write");
+		} catch (SerialPortException e) {
 			throw new IOException(e);
 		}
 	}
diff --git a/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java b/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java
index 1f4939c842..e6286d17d2 100644
--- a/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java
+++ b/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java
@@ -13,7 +13,7 @@ public class DesktopSystemModule extends AbstractModule {
 	protected void configure() {
 		bind(Clock.class).to(SystemClock.class);
 		bind(Timer.class).to(SystemTimer.class);
-		if(OsUtils.isLinux())
+		if (OsUtils.isLinux())
 			bind(SeedProvider.class).to(LinuxSeedProvider.class);
 		bind(FileUtils.class).to(DesktopFileUtils.class);
 	}
diff --git a/briar-tests/src/org/briarproject/LockFairnessTest.java b/briar-tests/src/org/briarproject/LockFairnessTest.java
index 5446225f29..30da3436b6 100644
--- a/briar-tests/src/org/briarproject/LockFairnessTest.java
+++ b/briar-tests/src/org/briarproject/LockFairnessTest.java
@@ -34,7 +34,7 @@ public class LockFairnessTest extends BriarTestCase {
 						// Release the lock
 						lock.readLock().unlock();
 					}
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					fail();
 				}
 				firstReaderHasFinished.countDown();
@@ -57,7 +57,7 @@ public class LockFairnessTest extends BriarTestCase {
 						// Release the lock
 						lock.readLock().unlock();
 					}
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					fail();
 				}
 				secondReaderHasFinished.countDown();
@@ -90,7 +90,7 @@ public class LockFairnessTest extends BriarTestCase {
 						// Allow the other threads to acquire the lock
 						firstReaderHasLock.countDown();
 						// Wait for both other threads to wait for the lock
-						while(lock.getQueueLength() < 2) Thread.sleep(10);
+						while (lock.getQueueLength() < 2) Thread.sleep(10);
 						// No other thread should have acquired the lock
 						assertFalse(secondReaderHasHeldLock.get());
 						assertFalse(writerHasHeldLock.get());
@@ -98,7 +98,7 @@ public class LockFairnessTest extends BriarTestCase {
 						// Release the lock
 						lock.readLock().unlock();
 					}
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					fail();
 				}
 				firstReaderHasFinished.countDown();
@@ -121,7 +121,7 @@ public class LockFairnessTest extends BriarTestCase {
 					} finally {
 						lock.writeLock().unlock();
 					}
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					fail();
 				}
 				writerHasFinished.countDown();
@@ -136,7 +136,7 @@ public class LockFairnessTest extends BriarTestCase {
 					// Wait for the first reader to acquire the lock
 					assertTrue(firstReaderHasLock.await(10, SECONDS));
 					// Wait for the writer to wait for the lock
-					while(lock.getQueueLength() < 1) Thread.sleep(10);
+					while (lock.getQueueLength() < 1) Thread.sleep(10);
 					// Acquire the lock
 					lock.readLock().lock();
 					try {
@@ -146,7 +146,7 @@ public class LockFairnessTest extends BriarTestCase {
 					} finally {
 						lock.readLock().unlock();
 					}
-				} catch(InterruptedException e) {
+				} catch (InterruptedException e) {
 					fail();
 				}
 				secondReaderHasFinished.countDown();
diff --git a/briar-tests/src/org/briarproject/TestUtils.java b/briar-tests/src/org/briarproject/TestUtils.java
index 40618408cf..861c866d85 100644
--- a/briar-tests/src/org/briarproject/TestUtils.java
+++ b/briar-tests/src/org/briarproject/TestUtils.java
@@ -16,7 +16,7 @@ public class TestUtils {
 	private static final Random random = new Random();
 
 	public static void delete(File f) {
-		if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
+		if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
 		f.delete();
 	}
 
@@ -47,7 +47,7 @@ public class TestUtils {
 
 	public static String createRandomString(int length) {
 		char[] c = new char[length];
-		for(int i = 0; i < length; i++)
+		for (int i = 0; i < length; i++)
 			c[i] = (char) ('a' + random.nextInt(26));
 		return new String(c);
 	}
diff --git a/briar-tests/src/org/briarproject/crypto/EllipticCurvePerformanceTest.java b/briar-tests/src/org/briarproject/crypto/EllipticCurvePerformanceTest.java
index fd876bc99e..84f2ca3c88 100644
--- a/briar-tests/src/org/briarproject/crypto/EllipticCurvePerformanceTest.java
+++ b/briar-tests/src/org/briarproject/crypto/EllipticCurvePerformanceTest.java
@@ -40,13 +40,13 @@ public class EllipticCurvePerformanceTest {
 			"brainpoolp256r1", "brainpoolp384r1", "brainpoolp512r1");
 
 	public static void main(String[] args) {
-		for(String name : SEC_NAMES) {
+		for (String name : SEC_NAMES) {
 			ECDomainParameters params =
 					convertParams(SECNamedCurves.getByName(name));
 			runTest(name + " default", params);
 			runTest(name + " constant", constantTime(params));
 		}
-		for(String name : BRAINPOOL_NAMES) {
+		for (String name : BRAINPOOL_NAMES) {
 			ECDomainParameters params =
 					convertParams(TeleTrusTNamedCurves.getByName(name));
 			runTest(name + " default", params);
@@ -71,7 +71,7 @@ public class EllipticCurvePerformanceTest {
 				(ECPublicKeyParameters) keyPair2.getPublic();
 		// Time some ECDH key agreements
 		List<Long> samples = new ArrayList<Long>();
-		for(int i = 0; i < SAMPLES; i++) {
+		for (int i = 0; i < SAMPLES; i++) {
 			ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
 			long start = System.nanoTime();
 			agreement.init(private1);
@@ -82,7 +82,7 @@ public class EllipticCurvePerformanceTest {
 		// Time some signatures
 		List<byte[]> signatures = new ArrayList<byte[]>();
 		samples.clear();
-		for(int i = 0; i < SAMPLES; i++) {
+		for (int i = 0; i < SAMPLES; i++) {
 			Digest digest = new SHA256Digest();
 			DSAKCalculator calculator = new HMacDSAKCalculator(digest);
 			DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(
@@ -96,7 +96,7 @@ public class EllipticCurvePerformanceTest {
 		long signatureMedian = median(samples);
 		// Time some signature verifications
 		samples.clear();
-		for(int i = 0; i < SAMPLES; i++) {
+		for (int i = 0; i < SAMPLES; i++) {
 			Digest digest = new SHA256Digest();
 			DSAKCalculator calculator = new HMacDSAKCalculator(digest);
 			DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(
@@ -104,7 +104,7 @@ public class EllipticCurvePerformanceTest {
 			long start = System.nanoTime();
 			signer.init(false, public1);
 			signer.update(new byte[BYTES_TO_SIGN], 0, BYTES_TO_SIGN);
-			if(!signer.verifySignature(signatures.get(i)))
+			if (!signer.verifySignature(signatures.get(i)))
 				throw new AssertionError();
 			samples.add(System.nanoTime() - start);
 		}
@@ -117,9 +117,9 @@ public class EllipticCurvePerformanceTest {
 
 	private static long median(List<Long> list) {
 		int size = list.size();
-		if(size == 0) throw new IllegalArgumentException();
+		if (size == 0) throw new IllegalArgumentException();
 		Collections.sort(list);
-		if(size % 2 == 1) return list.get(size / 2);
+		if (size % 2 == 1) return list.get(size / 2);
 		return list.get(size / 2 - 1) + list.get(size / 2) / 2;
 	}
 
diff --git a/briar-tests/src/org/briarproject/crypto/FortunaGeneratorTest.java b/briar-tests/src/org/briarproject/crypto/FortunaGeneratorTest.java
index fe083489aa..b3f92a65c7 100644
--- a/briar-tests/src/org/briarproject/crypto/FortunaGeneratorTest.java
+++ b/briar-tests/src/org/briarproject/crypto/FortunaGeneratorTest.java
@@ -23,7 +23,7 @@ public class FortunaGeneratorTest extends BriarTestCase {
 	public void testIncrementCounter() {
 		FortunaGenerator f = new FortunaGenerator(new byte[32]);
 		// Increment the counter until it reaches 255
-		for(int i = 1; i < 255; i++) f.incrementCounter();
+		for (int i = 1; i < 255; i++) f.incrementCounter();
 		byte[] expected = new byte[16];
 		expected[0] = (byte) 255;
 		assertArrayEquals(expected, f.getCounter());
@@ -33,7 +33,7 @@ public class FortunaGeneratorTest extends BriarTestCase {
 		expected[1] = 1;
 		assertArrayEquals(expected, f.getCounter());
 		// Increment the counter until it carries into the next byte
-		for(int i = 256; i < 65536; i++) f.incrementCounter();
+		for (int i = 256; i < 65536; i++) f.incrementCounter();
 		expected[0] = 0;
 		expected[1] = 0;
 		expected[2] = 1;
@@ -49,15 +49,15 @@ public class FortunaGeneratorTest extends BriarTestCase {
 		// One byte longer than a block, with an offset of one
 		byte[] out2 = new byte[49];
 		new FortunaGenerator(seed).nextBytes(out2, 1, 48);
-		for(int i = 0; i < 48; i++) assertEquals(out1[i], out2[i + 1]);
+		for (int i = 0; i < 48; i++) assertEquals(out1[i], out2[i + 1]);
 		// One byte shorter than a block
 		byte[] out3 = new byte[47];
 		new FortunaGenerator(seed).nextBytes(out3, 0, 47);
-		for(int i = 0; i < 47; i++) assertEquals(out1[i], out3[i]);
+		for (int i = 0; i < 47; i++) assertEquals(out1[i], out3[i]);
 		// Less than a block, with an offset greater than a block
 		byte[] out4 = new byte[32];
 		new FortunaGenerator(seed).nextBytes(out4, 17, 15);
-		for(int i = 0; i < 15; i++) assertEquals(out1[i], out4[i + 17]);
+		for (int i = 0; i < 15; i++) assertEquals(out1[i], out4[i + 17]);
 	}
 
 	@Test
diff --git a/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java b/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java
index d0d71a7eb7..631d0a44f3 100644
--- a/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java
+++ b/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java
@@ -29,9 +29,9 @@ public class KeyDerivationTest extends BriarTestCase {
 		keys.add(crypto.deriveFrameKey(secret, 0, false));
 		keys.add(crypto.deriveTagKey(secret, true));
 		keys.add(crypto.deriveTagKey(secret, false));
-		for(int i = 0; i < 4; i++) {
+		for (int i = 0; i < 4; i++) {
 			byte[] keyI = keys.get(i).getBytes();
-			for(int j = 0; j < 4; j++) {
+			for (int j = 0; j < 4; j++) {
 				byte[] keyJ = keys.get(j).getBytes();
 				assertEquals(i == j, Arrays.equals(keyI, keyJ));
 			}
@@ -42,14 +42,14 @@ public class KeyDerivationTest extends BriarTestCase {
 	public void testSecretAffectsDerivation() {
 		Random r = new Random();
 		List<byte[]> secrets = new ArrayList<byte[]>();
-		for(int i = 0; i < 20; i++) {
+		for (int i = 0; i < 20; i++) {
 			byte[] b = new byte[32];
 			r.nextBytes(b);
 			secrets.add(crypto.deriveNextSecret(b, 0));
 		}
-		for(int i = 0; i < 20; i++) {
+		for (int i = 0; i < 20; i++) {
 			byte[] secretI = secrets.get(i);
-			for(int j = 0; j < 20; j++) {
+			for (int j = 0; j < 20; j++) {
 				byte[] secretJ = secrets.get(j);
 				assertEquals(i == j, Arrays.equals(secretI, secretJ));
 			}
@@ -59,11 +59,11 @@ public class KeyDerivationTest extends BriarTestCase {
 	@Test
 	public void testStreamNumberAffectsDerivation() {
 		List<byte[]> secrets = new ArrayList<byte[]>();
-		for(int i = 0; i < 20; i++)
+		for (int i = 0; i < 20; i++)
 			secrets.add(crypto.deriveNextSecret(secret, i));
-		for(int i = 0; i < 20; i++) {
+		for (int i = 0; i < 20; i++) {
 			byte[] secretI = secrets.get(i);
-			for(int j = 0; j < 20; j++) {
+			for (int j = 0; j < 20; j++) {
 				byte[] secretJ = secrets.get(j);
 				assertEquals(i == j, Arrays.equals(secretI, secretJ));
 			}
diff --git a/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java b/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java
index 44b4d3a9fc..5a78c0cc86 100644
--- a/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java
+++ b/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java
@@ -63,19 +63,19 @@ public class KeyEncodingAndParsingTest extends BriarTestCase {
 		Random random = new Random();
 		byte[] pubFuzz = new byte[pubLength];
 		byte[] privFuzz = new byte[privLength];
-		for(int i = 0; i < 1000; i++) {
+		for (int i = 0; i < 1000; i++) {
 			random.nextBytes(pubFuzz);
 			try {
 				parser.parsePublicKey(pubFuzz);
-			} catch(GeneralSecurityException expected) {
-			} catch(Exception e) {
+			} catch (GeneralSecurityException expected) {
+			} catch (Exception e) {
 				fail();
 			}
 			random.nextBytes(privFuzz);
 			try {
 				parser.parsePrivateKey(privFuzz);
-			} catch(GeneralSecurityException expected) {
-			} catch(Exception e) {
+			} catch (GeneralSecurityException expected) {
+			} catch (Exception e) {
 				fail();
 			}
 		}
@@ -126,19 +126,19 @@ public class KeyEncodingAndParsingTest extends BriarTestCase {
 		Random random = new Random();
 		byte[] pubFuzz = new byte[pubLength];
 		byte[] privFuzz = new byte[privLength];
-		for(int i = 0; i < 1000; i++) {
+		for (int i = 0; i < 1000; i++) {
 			random.nextBytes(pubFuzz);
 			try {
 				parser.parsePublicKey(pubFuzz);
-			} catch(GeneralSecurityException expected) {
-			} catch(Exception e) {
+			} catch (GeneralSecurityException expected) {
+			} catch (Exception e) {
 				fail();
 			}
 			random.nextBytes(privFuzz);
 			try {
 				parser.parsePrivateKey(privFuzz);
-			} catch(GeneralSecurityException expected) {
-			} catch(Exception e) {
+			} catch (GeneralSecurityException expected) {
+			} catch (Exception e) {
 				fail();
 			}
 		}
diff --git a/briar-tests/src/org/briarproject/crypto/TestAuthenticatedCipher.java b/briar-tests/src/org/briarproject/crypto/TestAuthenticatedCipher.java
index 3861318177..7e960613f8 100644
--- a/briar-tests/src/org/briarproject/crypto/TestAuthenticatedCipher.java
+++ b/briar-tests/src/org/briarproject/crypto/TestAuthenticatedCipher.java
@@ -17,14 +17,14 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
 
 	public int process(byte[] input, int inputOff, int len, byte[] output,
 			int outputOff) throws GeneralSecurityException {
-		if(encrypt) {
+		if (encrypt) {
 			System.arraycopy(input, inputOff, output, outputOff, len);
-			for(int i = 0; i < MAC_LENGTH; i++)
+			for (int i = 0; i < MAC_LENGTH; i++)
 				output[outputOff + len + i] = 0;
 			return len + MAC_LENGTH;
 		} else {
-			for(int i = 0; i < MAC_LENGTH; i++)
-				if(input[inputOff + len - MAC_LENGTH + i] != 0)
+			for (int i = 0; i < MAC_LENGTH; i++)
+				if (input[inputOff + len - MAC_LENGTH + i] != 0)
 					throw new GeneralSecurityException();
 			System.arraycopy(input, inputOff, output, outputOff,
 					len - MAC_LENGTH);
diff --git a/briar-tests/src/org/briarproject/data/ReaderImplTest.java b/briar-tests/src/org/briarproject/data/ReaderImplTest.java
index 1b14d3c17e..da9276279b 100644
--- a/briar-tests/src/org/briarproject/data/ReaderImplTest.java
+++ b/briar-tests/src/org/briarproject/data/ReaderImplTest.java
@@ -131,39 +131,39 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readInteger();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 		setContents("21" + "80" + "22" + "FF80");
 		assertEquals(Byte.MIN_VALUE, r.readInteger());
 		try {
 			r.readInteger();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 		// INTEGER_32 could be encoded as INTEGER_16
 		setContents("22" + "7FFF" + "24" + "00007FFF");
 		assertEquals(Short.MAX_VALUE, r.readInteger());
 		try {
 			r.readInteger();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 		setContents("22" + "8000" + "24" + "FFFF8000");
 		assertEquals(Short.MIN_VALUE, r.readInteger());
 		try {
 			r.readInteger();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 		// INTEGER_64 could be encoded as INTEGER_32
 		setContents("24" + "7FFFFFFF" + "28" + "000000007FFFFFFF");
 		assertEquals(Integer.MAX_VALUE, r.readInteger());
 		try {
 			r.readInteger();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 		setContents("24" + "80000000" + "28" + "FFFFFFFF80000000");
 		assertEquals(Integer.MIN_VALUE, r.readInteger());
 		try {
 			r.readInteger();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -214,7 +214,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readString(2);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -254,7 +254,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readString(Byte.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -292,7 +292,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readString(Short.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -317,7 +317,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readString(Integer.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 		// STRING_32 could be encoded as STRING_16
 		String longest16 = TestUtils.createRandomString(Short.MAX_VALUE);
 		String long16Hex = StringUtils.toHexString(longest16.getBytes("UTF-8"));
@@ -326,7 +326,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readString(Integer.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -351,7 +351,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readRaw(2);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -391,7 +391,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readRaw(Byte.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -429,7 +429,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readRaw(Short.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -454,7 +454,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readRaw(Integer.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 		// RAW_32 could be encoded as RAW_16
 		byte[] longest16 = new byte[Short.MAX_VALUE];
 		String long16Hex = StringUtils.toHexString(longest16);
@@ -463,7 +463,7 @@ public class ReaderImplTest extends BriarTestCase {
 		try {
 			r.readRaw(Integer.MAX_VALUE);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
diff --git a/briar-tests/src/org/briarproject/data/WriterImplTest.java b/briar-tests/src/org/briarproject/data/WriterImplTest.java
index 05cf0875a4..7697bdd77a 100644
--- a/briar-tests/src/org/briarproject/data/WriterImplTest.java
+++ b/briar-tests/src/org/briarproject/data/WriterImplTest.java
@@ -146,7 +146,7 @@ public class WriterImplTest extends BriarTestCase {
 	@Test
 	public void testWriteList() throws IOException {
 		List<Object> l = new ArrayList<Object>();
-		for(int i = 0; i < 3; i++) l.add(i);
+		for (int i = 0; i < 3; i++) l.add(i);
 		w.writeList(l);
 		// LIST tag, elements as integers, END tag
 		checkContents("60" + "21" + "00" + "21" + "01" + "21" + "02" + "80");
@@ -167,7 +167,7 @@ public class WriterImplTest extends BriarTestCase {
 	public void testWriteMap() throws IOException {
 		// Use LinkedHashMap to get predictable iteration order
 		Map<String, Object> m = new LinkedHashMap<String, Object>();
-		for(int i = 0; i < 4; i++) m.put(String.valueOf(i), i);
+		for (int i = 0; i < 4; i++) m.put(String.valueOf(i), i);
 		w.writeMap(m);
 		// MAP tag, keys as strings and values as integers, END tag
 		checkContents("70" + "41" + "01" + "30" + "21" + "00" +
diff --git a/briar-tests/src/org/briarproject/db/BasicH2Test.java b/briar-tests/src/org/briarproject/db/BasicH2Test.java
index bf490af013..c5ca6af83b 100644
--- a/briar-tests/src/org/briarproject/db/BasicH2Test.java
+++ b/briar-tests/src/org/briarproject/db/BasicH2Test.java
@@ -74,7 +74,7 @@ public class BasicH2Test extends BriarTestCase {
 		String[] oldNames = new String[BATCH_SIZE];
 		String[] newNames = new String[BATCH_SIZE];
 		Random random = new Random();
-		for(int i = 0; i < BATCH_SIZE; i++) {
+		for (int i = 0; i < BATCH_SIZE; i++) {
 			random.nextBytes(ids[i]);
 			oldNames[i] = TestUtils.createRandomString(50);
 			newNames[i] = TestUtils.createRandomString(50);
@@ -84,20 +84,20 @@ public class BasicH2Test extends BriarTestCase {
 		// Update the names as a batch
 		updateBatch(ids, newNames);
 		// Check that the new names can be retrieved using the IDs
-		for(int i = 0; i < BATCH_SIZE; i++) {
+		for (int i = 0; i < BATCH_SIZE; i++) {
 			assertTrue(rowExists(ids[i]));
 			assertEquals(newNames[i], getName(ids[i]));
 		}
 		// Delete the rows as a batch
 		boolean[] deleted = deleteBatch(ids);
 		// Check that the rows no longer exist
-		for(int i = 0; i < BATCH_SIZE; i++) {
+		for (int i = 0; i < BATCH_SIZE; i++) {
 			assertTrue(deleted[i]);
 			assertFalse(rowExists(ids[i]));
 		}
 		// Deleting the rows again should have no effect
 		deleted = deleteBatch(ids);
-		for(int i = 0; i < BATCH_SIZE; i++) assertFalse(deleted[i]);
+		for (int i = 0; i < BATCH_SIZE; i++) assertFalse(deleted[i]);
 	}
 
 	@Test
@@ -146,7 +146,7 @@ public class BasicH2Test extends BriarTestCase {
 			Statement s = connection.createStatement();
 			s.executeUpdate(CREATE_TABLE);
 			s.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -156,13 +156,13 @@ public class BasicH2Test extends BriarTestCase {
 		String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
 		try {
 			PreparedStatement ps = connection.prepareStatement(sql);
-			if(id == null) ps.setNull(1, BINARY);
+			if (id == null) ps.setNull(1, BINARY);
 			else ps.setBytes(1, id);
 			ps.setString(2, name);
 			int affected = ps.executeUpdate();
 			assertEquals(1, affected);
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -180,7 +180,7 @@ public class BasicH2Test extends BriarTestCase {
 			rs.close();
 			ps.close();
 			return found;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -199,7 +199,7 @@ public class BasicH2Test extends BriarTestCase {
 			rs.close();
 			ps.close();
 			return name;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -209,12 +209,12 @@ public class BasicH2Test extends BriarTestCase {
 		String sql = "UPDATE foo SET name = ? WHERE uniqueId = ?";
 		try {
 			PreparedStatement ps = connection.prepareStatement(sql);
-			if(id == null) ps.setNull(2, BINARY);
+			if (id == null) ps.setNull(2, BINARY);
 			else ps.setBytes(2, id);
 			ps.setString(1, name);
 			assertEquals(1, ps.executeUpdate());
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -224,12 +224,12 @@ public class BasicH2Test extends BriarTestCase {
 		String sql = "DELETE FROM foo WHERE uniqueId = ?";
 		try {
 			PreparedStatement ps = connection.prepareStatement(sql);
-			if(id == null) ps.setNull(1, BINARY);
+			if (id == null) ps.setNull(1, BINARY);
 			else ps.setBytes(1, id);
 			int affected = ps.executeUpdate();
 			ps.close();
 			return affected == 1;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -240,19 +240,19 @@ public class BasicH2Test extends BriarTestCase {
 		String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
 		try {
 			PreparedStatement ps = connection.prepareStatement(sql);
-			for(int i = 0; i < ids.length; i++) {
-				if(ids[i] == null) ps.setNull(1, BINARY);
+			for (int i = 0; i < ids.length; i++) {
+				if (ids[i] == null) ps.setNull(1, BINARY);
 				else ps.setBytes(1, ids[i]);
 				ps.setString(2, names[i]);
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
 			assertEquals(ids.length, batchAffected.length);
-			for(int i = 0; i < batchAffected.length; i++) {
+			for (int i = 0; i < batchAffected.length; i++) {
 				assertEquals(1, batchAffected[i]);
 			}
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -263,18 +263,18 @@ public class BasicH2Test extends BriarTestCase {
 		String sql = "UPDATE foo SET name = ? WHERE uniqueId = ?";
 		try {
 			PreparedStatement ps = connection.prepareStatement(sql);
-			for(int i = 0; i < ids.length; i++) {
-				if(ids[i] == null) ps.setNull(2, BINARY);
+			for (int i = 0; i < ids.length; i++) {
+				if (ids[i] == null) ps.setNull(2, BINARY);
 				else ps.setBytes(2, ids[i]);
 				ps.setString(1, names[i]);
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
 			assertEquals(ids.length, batchAffected.length);
-			for(int i = 0; i < batchAffected.length; i++)
+			for (int i = 0; i < batchAffected.length; i++)
 				assertEquals(1, batchAffected[i]);
 			ps.close();
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -284,19 +284,19 @@ public class BasicH2Test extends BriarTestCase {
 		String sql = "DELETE FROM foo WHERE uniqueId = ?";
 		try {
 			PreparedStatement ps = connection.prepareStatement(sql);
-			for(int i = 0; i < ids.length; i++) {
-				if(ids[i] == null) ps.setNull(1, BINARY);
+			for (int i = 0; i < ids.length; i++) {
+				if (ids[i] == null) ps.setNull(1, BINARY);
 				else ps.setBytes(1, ids[i]);
 				ps.addBatch();
 			}
 			int[] batchAffected = ps.executeBatch();
 			assertEquals(ids.length, batchAffected.length);
 			boolean[] ret = new boolean[ids.length];
-			for(int i = 0; i < batchAffected.length; i++)
+			for (int i = 0; i < batchAffected.length; i++)
 				ret[i] = batchAffected[i] == 1;
 			ps.close();
 			return ret;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -315,7 +315,7 @@ public class BasicH2Test extends BriarTestCase {
 			rs.close();
 			ps.close();
 			return name;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -327,11 +327,11 @@ public class BasicH2Test extends BriarTestCase {
 		try {
 			PreparedStatement ps = connection.prepareStatement(sql);
 			ResultSet rs = ps.executeQuery();
-			while(rs.next()) names.add(rs.getString(1));
+			while (rs.next()) names.add(rs.getString(1));
 			rs.close();
 			ps.close();
 			return names;
-		} catch(SQLException e) {
+		} catch (SQLException e) {
 			connection.close();
 			throw e;
 		}
@@ -339,7 +339,7 @@ public class BasicH2Test extends BriarTestCase {
 
 	@After
 	public void tearDown() throws Exception {
-		if(connection != null) connection.close();
+		if (connection != null) connection.close();
 		TestUtils.deleteTestDirectory(testDir);
 	}
 }
diff --git a/briar-tests/src/org/briarproject/db/DatabaseCleanerImplTest.java b/briar-tests/src/org/briarproject/db/DatabaseCleanerImplTest.java
index 222ec47dbd..093680f3b5 100644
--- a/briar-tests/src/org/briarproject/db/DatabaseCleanerImplTest.java
+++ b/briar-tests/src/org/briarproject/db/DatabaseCleanerImplTest.java
@@ -39,7 +39,7 @@ public class DatabaseCleanerImplTest extends BriarTestCase {
 		// Start the cleaner - it should schedule itself with the timer
 		cleaner.startCleaning(callback, 10);
 		// Call the cleaner's run method six times
-		for(int i = 0; i < 6; i++) cleaner.run();
+		for (int i = 0; i < 6; i++) cleaner.run();
 		// Stop the cleaner - it should cancel the timer
 		cleaner.stopCleaning();
 		// The database should have been cleaned three times
diff --git a/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java b/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java
index 338b8c9577..645ce2fb18 100644
--- a/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java
+++ b/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java
@@ -332,137 +332,137 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
 		try {
 			db.addEndpoint(endpoint);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateAck(contactId, 123);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateBatch(contactId, 123, 456);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateOffer(contactId, 123, 456);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateRetentionAck(contactId);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateRetentionUpdate(contactId, 123);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateSubscriptionAck(contactId);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateSubscriptionUpdate(contactId, 123);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateTransportAcks(contactId);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.generateTransportUpdates(contactId, 123);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.getContact(contactId);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.getInboxGroupId(contactId);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.incrementStreamCounter(contactId, transportId, 0);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			Ack a = new Ack(Arrays.asList(messageId));
 			db.receiveAck(contactId, a);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.receiveMessage(contactId, message);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			Offer o = new Offer(Arrays.asList(messageId));
 			db.receiveOffer(contactId, o);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			RetentionAck a = new RetentionAck(0);
 			db.receiveRetentionAck(contactId, a);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			RetentionUpdate u = new RetentionUpdate(0, 1);
 			db.receiveRetentionUpdate(contactId, u);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			SubscriptionAck a = new SubscriptionAck(0);
 			db.receiveSubscriptionAck(contactId, a);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			SubscriptionUpdate u = new SubscriptionUpdate(
 					Collections.<Group>emptyList(), 1);
 			db.receiveSubscriptionUpdate(contactId, u);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			TransportAck a = new TransportAck(transportId, 0);
 			db.receiveTransportAck(contactId, a);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			TransportUpdate u = new TransportUpdate(transportId,
 					transportProperties, 1);
 			db.receiveTransportUpdate(contactId, u);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.removeContact(contactId);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		try {
 			db.setInboxGroup(contactId, group);
 			fail();
-		} catch(NoSuchContactException expected) {}
+		} catch (NoSuchContactException expected) {}
 
 		context.assertIsSatisfied();
 	}
@@ -493,17 +493,17 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
 		try {
 			db.addContact(author, localAuthorId);
 			fail();
-		} catch(NoSuchLocalAuthorException expected) {}
+		} catch (NoSuchLocalAuthorException expected) {}
 
 		try {
 			db.getLocalAuthor(localAuthorId);
 			fail();
-		} catch(NoSuchLocalAuthorException expected) {}
+		} catch (NoSuchLocalAuthorException expected) {}
 
 		try {
 			db.removeLocalAuthor(localAuthorId);
 			fail();
-		} catch(NoSuchLocalAuthorException expected) {}
+		} catch (NoSuchLocalAuthorException expected) {}
 
 		context.assertIsSatisfied();
 	}
@@ -531,27 +531,27 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
 		try {
 			db.getGroup(groupId);
 			fail();
-		} catch(NoSuchSubscriptionException expected) {}
+		} catch (NoSuchSubscriptionException expected) {}
 
 		try {
 			db.getMessageHeaders(groupId);
 			fail();
-		} catch(NoSuchSubscriptionException expected) {}
+		} catch (NoSuchSubscriptionException expected) {}
 
 		try {
 			db.getVisibility(groupId);
 			fail();
-		} catch(NoSuchSubscriptionException expected) {}
+		} catch (NoSuchSubscriptionException expected) {}
 
 		try {
 			db.removeGroup(group);
 			fail();
-		} catch(NoSuchSubscriptionException expected) {}
+		} catch (NoSuchSubscriptionException expected) {}
 
 		try {
 			db.setVisibility(groupId, Collections.<ContactId>emptyList());
 			fail();
-		} catch(NoSuchSubscriptionException expected) {}
+		} catch (NoSuchSubscriptionException expected) {}
 
 		context.assertIsSatisfied();
 	}
@@ -603,42 +603,42 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
 		try {
 			db.addEndpoint(endpoint);
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		try {
 			db.getConfig(transportId);
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		try {
 			db.getLocalProperties(transportId);
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		try {
 			db.mergeConfig(transportId, new TransportConfig());
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		try {
 			db.mergeLocalProperties(transportId, new TransportProperties());
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		try {
 			db.incrementStreamCounter(contactId, transportId, 0);
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		try {
 			db.removeTransport(transportId);
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		try {
 			db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
 			fail();
-		} catch(NoSuchTransportException expected) {}
+		} catch (NoSuchTransportException expected) {}
 
 		context.assertIsSatisfied();
 	}
diff --git a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java
index 6e2d634dd1..ec21e4c6c0 100644
--- a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java
+++ b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java
@@ -418,7 +418,7 @@ public class H2DatabaseTest extends BriarTestCase {
 
 		// Allowing enough capacity for both messages should return both
 		Collection<MessageId> ids = new HashSet<MessageId>();
-		for(MessageId id : db.getOldMessages(txn, size * 2)) ids.add(id);
+		for (MessageId id : db.getOldMessages(txn, size * 2)) ids.add(id);
 		assertEquals(2, ids.size());
 		assertTrue(ids.contains(messageId));
 		assertTrue(ids.contains(messageId1));
@@ -430,7 +430,7 @@ public class H2DatabaseTest extends BriarTestCase {
 	@Test
 	public void testGetFreeSpace() throws Exception {
 		byte[] largeBody = new byte[ONE_MEGABYTE];
-		for(int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
+		for (int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
 		Message message = new TestMessage(messageId, null, group, author,
 				contentType, subject, timestamp, largeBody);
 		Database<Connection> db = open(false);
@@ -470,9 +470,9 @@ public class H2DatabaseTest extends BriarTestCase {
 				try {
 					closing.countDown();
 					db.close();
-					if(!transactionFinished.get()) error.set(true);
+					if (!transactionFinished.get()) error.set(true);
 					closed.countDown();
-				} catch(Exception e) {
+				} catch (Exception e) {
 					error.set(true);
 				}
 			}
@@ -507,9 +507,9 @@ public class H2DatabaseTest extends BriarTestCase {
 				try {
 					closing.countDown();
 					db.close();
-					if(!transactionFinished.get()) error.set(true);
+					if (!transactionFinished.get()) error.set(true);
 					closed.countDown();
-				} catch(Exception e) {
+				} catch (Exception e) {
 					error.set(true);
 				}
 			}
@@ -903,12 +903,12 @@ public class H2DatabaseTest extends BriarTestCase {
 		Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId);
 		assertEquals(2, headers.size());
 		boolean firstFound = false, secondFound = false;
-		for(MessageHeader header : headers) {
-			if(messageId.equals(header.getId())) {
+		for (MessageHeader header : headers) {
+			if (messageId.equals(header.getId())) {
 				assertHeadersMatch(message, header);
 				assertTrue(header.isRead());
 				firstFound = true;
-			} else if(messageId1.equals(header.getId())) {
+			} else if (messageId1.equals(header.getId())) {
 				assertHeadersMatch(message1, header);
 				assertFalse(header.isRead());
 				secondFound = true;
@@ -926,10 +926,10 @@ public class H2DatabaseTest extends BriarTestCase {
 
 	private void assertHeadersMatch(Message m, MessageHeader h) {
 		assertEquals(m.getId(), h.getId());
-		if(m.getParent() == null) assertNull(h.getParent());
+		if (m.getParent() == null) assertNull(h.getParent());
 		else assertEquals(m.getParent(), h.getParent());
 		assertEquals(m.getGroup().getId(), h.getGroupId());
-		if(m.getAuthor() == null) assertNull(h.getAuthor());
+		if (m.getAuthor() == null) assertNull(h.getAuthor());
 		else assertEquals(m.getAuthor(), h.getAuthor());
 		assertEquals(m.getContentType(), h.getContentType());
 		assertEquals(m.getTimestamp(), h.getTimestamp());
@@ -965,16 +965,16 @@ public class H2DatabaseTest extends BriarTestCase {
 		Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId);
 		assertEquals(3, headers.size());
 		boolean firstFound = false, secondFound = false, thirdFound = false;
-		for(MessageHeader header : headers) {
-			if(messageId.equals(header.getId())) {
+		for (MessageHeader header : headers) {
+			if (messageId.equals(header.getId())) {
 				assertHeadersMatch(message, header);
 				assertEquals(Author.Status.VERIFIED, header.getAuthorStatus());
 				firstFound = true;
-			} else if(messageId1.equals(header.getId())) {
+			} else if (messageId1.equals(header.getId())) {
 				assertHeadersMatch(message1, header);
 				assertEquals(Author.Status.UNKNOWN, header.getAuthorStatus());
 				secondFound = true;
-			} else if(messageId2.equals(header.getId())) {
+			} else if (messageId2.equals(header.getId())) {
 				assertHeadersMatch(message2, header);
 				assertEquals(Author.Status.ANONYMOUS, header.getAuthorStatus());
 				thirdFound = true;
@@ -1075,7 +1075,7 @@ public class H2DatabaseTest extends BriarTestCase {
 	public void testMultipleSubscriptionsAndUnsubscriptions() throws Exception {
 		// Create some groups
 		List<Group> groups = new ArrayList<Group>();
-		for(int i = 0; i < 100; i++) {
+		for (int i = 0; i < 100; i++) {
 			GroupId id = new GroupId(TestUtils.getRandomId());
 			String name = "Group " + i;
 			groups.add(new Group(id, name, new byte[GROUP_SALT_LENGTH]));
@@ -1087,16 +1087,16 @@ public class H2DatabaseTest extends BriarTestCase {
 		// Add a contact and subscribe to the groups
 		db.addLocalAuthor(txn, localAuthor);
 		assertEquals(contactId, db.addContact(txn, author, localAuthorId));
-		for(Group g : groups) db.addGroup(txn, g);
+		for (Group g : groups) db.addGroup(txn, g);
 
 		// Make the groups visible to the contact
 		Collections.shuffle(groups);
-		for(Group g : groups) db.addVisibility(txn, contactId, g.getId());
+		for (Group g : groups) db.addVisibility(txn, contactId, g.getId());
 
 		// Make some of the groups invisible to the contact and remove them all
 		Collections.shuffle(groups);
-		for(Group g : groups) {
-			if(Math.random() < 0.5)
+		for (Group g : groups) {
+			if (Math.random() < 0.5)
 				db.removeVisibility(txn, contactId, g.getId());
 			db.removeGroup(txn, g.getId());
 		}
@@ -1156,24 +1156,24 @@ public class H2DatabaseTest extends BriarTestCase {
 		Collection<TemporarySecret> secrets = db.getSecrets(txn);
 		assertEquals(3, secrets.size());
 		boolean foundFirst = false, foundSecond = false, foundThird = false;
-		for(TemporarySecret s : secrets) {
+		for (TemporarySecret s : secrets) {
 			assertEquals(contactId, s.getContactId());
 			assertEquals(transportId, s.getTransportId());
 			assertEquals(epoch, s.getEpoch());
 			assertEquals(alice, s.getAlice());
-			if(s.getPeriod() == 0) {
+			if (s.getPeriod() == 0) {
 				assertArrayEquals(secret1, s.getSecret());
 				assertEquals(outgoing1, s.getOutgoingStreamCounter());
 				assertEquals(centre1, s.getWindowCentre());
 				assertArrayEquals(bitmap1, s.getWindowBitmap());
 				foundFirst = true;
-			} else if(s.getPeriod() == 1) {
+			} else if (s.getPeriod() == 1) {
 				assertArrayEquals(secret2, s.getSecret());
 				assertEquals(outgoing2, s.getOutgoingStreamCounter());
 				assertEquals(centre2, s.getWindowCentre());
 				assertArrayEquals(bitmap2, s.getWindowBitmap());
 				foundSecond = true;
-			} else if(s.getPeriod() == 2) {
+			} else if (s.getPeriod() == 2) {
 				assertArrayEquals(secret3, s.getSecret());
 				assertEquals(outgoing3, s.getOutgoingStreamCounter());
 				assertEquals(centre3, s.getWindowCentre());
@@ -1193,24 +1193,24 @@ public class H2DatabaseTest extends BriarTestCase {
 		assertEquals(3, secrets.size());
 		foundSecond = foundThird = false;
 		boolean foundFourth = false;
-		for(TemporarySecret s : secrets) {
+		for (TemporarySecret s : secrets) {
 			assertEquals(contactId, s.getContactId());
 			assertEquals(transportId, s.getTransportId());
 			assertEquals(epoch, s.getEpoch());
 			assertEquals(alice, s.getAlice());
-			if(s.getPeriod() == 1) {
+			if (s.getPeriod() == 1) {
 				assertArrayEquals(secret2, s.getSecret());
 				assertEquals(outgoing2, s.getOutgoingStreamCounter());
 				assertEquals(centre2, s.getWindowCentre());
 				assertArrayEquals(bitmap2, s.getWindowBitmap());
 				foundSecond = true;
-			} else if(s.getPeriod() == 2) {
+			} else if (s.getPeriod() == 2) {
 				assertArrayEquals(secret3, s.getSecret());
 				assertEquals(outgoing3, s.getOutgoingStreamCounter());
 				assertEquals(centre3, s.getWindowCentre());
 				assertArrayEquals(bitmap3, s.getWindowBitmap());
 				foundThird = true;
-			} else if(s.getPeriod() == 3) {
+			} else if (s.getPeriod() == 3) {
 				assertArrayEquals(secret4, s.getSecret());
 				assertEquals(outgoing4, s.getOutgoingStreamCounter());
 				assertEquals(centre4, s.getWindowCentre());
@@ -1387,13 +1387,13 @@ public class H2DatabaseTest extends BriarTestCase {
 		Collection<Endpoint> endpoints = db.getEndpoints(txn);
 		assertEquals(2, endpoints.size());
 		boolean foundFirst = false, foundSecond = false;
-		for(Endpoint ep : endpoints) {
+		for (Endpoint ep : endpoints) {
 			assertEquals(contactId, ep.getContactId());
-			if(ep.getTransportId().equals(transportId1)) {
+			if (ep.getTransportId().equals(transportId1)) {
 				assertEquals(epoch1, ep.getEpoch());
 				assertEquals(alice1, ep.getAlice());
 				foundFirst = true;
-			} else if(ep.getTransportId().equals(transportId2)) {
+			} else if (ep.getTransportId().equals(transportId2)) {
 				assertEquals(epoch2, ep.getEpoch());
 				assertEquals(alice2, ep.getAlice());
 				foundSecond = true;
@@ -1530,7 +1530,7 @@ public class H2DatabaseTest extends BriarTestCase {
 
 		// Add some offered messages and count them
 		List<MessageId> ids = new ArrayList<MessageId>();
-		for(int i = 0; i < 10; i++) {
+		for (int i = 0; i < 10; i++) {
 			MessageId m = new MessageId(TestUtils.getRandomId());
 			db.addOfferedMessage(txn, contactId, m);
 			ids.add(m);
@@ -1595,7 +1595,7 @@ public class H2DatabaseTest extends BriarTestCase {
 			// Ask for a nonexistent message - an exception should be thrown
 			db.getRawMessage(txn, messageId);
 			fail();
-		} catch(DbException expected) {
+		} catch (DbException expected) {
 			// It should be possible to abort the transaction without error
 			db.abortTransaction(txn);
 		}
@@ -1606,7 +1606,7 @@ public class H2DatabaseTest extends BriarTestCase {
 	private Database<Connection> open(boolean resume) throws Exception {
 		Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
 				MAX_SIZE), new TestFileUtils(), new SystemClock());
-		if(!resume) TestUtils.deleteTestDirectory(testDir);
+		if (!resume) TestUtils.deleteTestDirectory(testDir);
 		db.open();
 		return db;
 	}
diff --git a/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java b/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java
index 8243cd4641..6b6942d269 100644
--- a/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java
+++ b/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java
@@ -13,7 +13,7 @@ public class ShutdownManagerImplTest extends BriarTestCase {
 	public void testAddAndRemove() {
 		ShutdownManager s = createShutdownManager();
 		Set<Integer> handles = new HashSet<Integer>();
-		for(int i = 0; i < 100; i++) {
+		for (int i = 0; i < 100; i++) {
 			int handle = s.addShutdownHook(new Runnable() {
 				public void run() {}
 			});
@@ -21,9 +21,9 @@ public class ShutdownManagerImplTest extends BriarTestCase {
 			assertTrue(handles.add(handle));
 		}
 		// The hooks should be removable
-		for(int handle : handles) assertTrue(s.removeShutdownHook(handle));
+		for (int handle : handles) assertTrue(s.removeShutdownHook(handle));
 		// The hooks should no longer be removable
-		for(int handle : handles) assertFalse(s.removeShutdownHook(handle));
+		for (int handle : handles) assertFalse(s.removeShutdownHook(handle));
 	}
 
 	protected ShutdownManager createShutdownManager() {
diff --git a/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java b/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java
index d93f42d05b..53b5623963 100644
--- a/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java
+++ b/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java
@@ -14,12 +14,12 @@ public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
 	public void testManagerWaitsForHooksToRun() {
 		WindowsShutdownManagerImpl s = new WindowsShutdownManagerImpl();
 		SlowHook[] hooks = new SlowHook[10];
-		for(int i = 0; i < hooks.length; i++) {
+		for (int i = 0; i < hooks.length; i++) {
 			hooks[i] = new SlowHook();
 			s.addShutdownHook(hooks[i]);
 		}
 		s.runShutdownHooks();
-		for(int i = 0; i < hooks.length; i++) assertTrue(hooks[i].finished);
+		for (int i = 0; i < hooks.length; i++) assertTrue(hooks[i].finished);
 	}
 
 	private static class SlowHook implements Runnable {
@@ -30,7 +30,7 @@ public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
 			try {
 				Thread.sleep(100);
 				finished = true;
-			} catch(InterruptedException e) {
+			} catch (InterruptedException e) {
 				fail();
 			}
 		}
diff --git a/briar-tests/src/org/briarproject/messaging/ConstantsTest.java b/briar-tests/src/org/briarproject/messaging/ConstantsTest.java
index 9839831582..4eecb2c278 100644
--- a/briar-tests/src/org/briarproject/messaging/ConstantsTest.java
+++ b/briar-tests/src/org/briarproject/messaging/ConstantsTest.java
@@ -75,7 +75,7 @@ public class ConstantsTest extends BriarTestCase {
 	@Test
 	public void testAgreementPublicKeys() throws Exception {
 		// Generate 10 agreement key pairs
-		for(int i = 0; i < 10; i++) {
+		for (int i = 0; i < 10; i++) {
 			KeyPair keyPair = crypto.generateSignatureKeyPair();
 			// Check the length of the public key
 			byte[] publicKey = keyPair.getPublic().getEncoded();
@@ -88,7 +88,7 @@ public class ConstantsTest extends BriarTestCase {
 		Random random = new Random();
 		Signature sig = crypto.getSignature();
 		// Generate 10 signature key pairs
-		for(int i = 0; i < 10; i++) {
+		for (int i = 0; i < 10; i++) {
 			KeyPair keyPair = crypto.generateSignatureKeyPair();
 			// Check the length of the public key
 			byte[] publicKey = keyPair.getPublic().getEncoded();
@@ -166,7 +166,7 @@ public class ConstantsTest extends BriarTestCase {
 	public void testPropertiesFitIntoTransportUpdate() throws Exception {
 		// Create the maximum number of properties with the maximum length
 		TransportProperties p = new TransportProperties();
-		for(int i = 0; i < MAX_PROPERTIES_PER_TRANSPORT; i++) {
+		for (int i = 0; i < MAX_PROPERTIES_PER_TRANSPORT; i++) {
 			String key = TestUtils.createRandomString(MAX_PROPERTY_LENGTH);
 			String value = TestUtils.createRandomString(MAX_PROPERTY_LENGTH);
 			p.put(key, value);
@@ -187,7 +187,7 @@ public class ConstantsTest extends BriarTestCase {
 	public void testGroupsFitIntoSubscriptionUpdate() throws Exception {
 		// Create the maximum number of maximum-length groups
 		Collection<Group> groups = new ArrayList<Group>();
-		for(int i = 0; i < MAX_SUBSCRIPTIONS; i++) {
+		for (int i = 0; i < MAX_SUBSCRIPTIONS; i++) {
 			String name = TestUtils.createRandomString(MAX_GROUP_NAME_LENGTH);
 			groups.add(groupFactory.createGroup(name));
 		}
@@ -207,7 +207,7 @@ public class ConstantsTest extends BriarTestCase {
 		PacketWriter writer = packetWriterFactory.createPacketWriter(out);
 		int maxMessages = writer.getMaxMessagesForAck(length);
 		Collection<MessageId> ids = new ArrayList<MessageId>();
-		for(int i = 0; i < maxMessages; i++)
+		for (int i = 0; i < maxMessages; i++)
 			ids.add(new MessageId(TestUtils.getRandomId()));
 		writer.writeAck(new Ack(ids));
 		// Check the size of the serialised ack
@@ -220,7 +220,7 @@ public class ConstantsTest extends BriarTestCase {
 		PacketWriter writer = packetWriterFactory.createPacketWriter(out);
 		int maxMessages = writer.getMaxMessagesForRequest(length);
 		Collection<MessageId> ids = new ArrayList<MessageId>();
-		for(int i = 0; i < maxMessages; i++)
+		for (int i = 0; i < maxMessages; i++)
 			ids.add(new MessageId(TestUtils.getRandomId()));
 		writer.writeRequest(new Request(ids));
 		// Check the size of the serialised request
@@ -233,7 +233,7 @@ public class ConstantsTest extends BriarTestCase {
 		PacketWriter writer = packetWriterFactory.createPacketWriter(out);
 		int maxMessages = writer.getMaxMessagesForOffer(length);
 		Collection<MessageId> ids = new ArrayList<MessageId>();
-		for(int i = 0; i < maxMessages; i++)
+		for (int i = 0; i < maxMessages; i++)
 			ids.add(new MessageId(TestUtils.getRandomId()));
 		writer.writeOffer(new Offer(ids));
 		// Check the size of the serialised offer
diff --git a/briar-tests/src/org/briarproject/messaging/ConsumersTest.java b/briar-tests/src/org/briarproject/messaging/ConsumersTest.java
index a9470f5cd7..c1c404c8ba 100644
--- a/briar-tests/src/org/briarproject/messaging/ConsumersTest.java
+++ b/briar-tests/src/org/briarproject/messaging/ConsumersTest.java
@@ -40,7 +40,7 @@ public class ConsumersTest extends BriarTestCase {
 		try {
 			cc.write((byte) 0);
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
diff --git a/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java b/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java
index 1f4f55e91a..1ce59e04e8 100644
--- a/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java
+++ b/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java
@@ -46,7 +46,7 @@ public class PacketReaderImplTest extends BriarTestCase {
 		try {
 			reader.readAck();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -67,7 +67,7 @@ public class PacketReaderImplTest extends BriarTestCase {
 		try {
 			reader.readAck();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -79,7 +79,7 @@ public class PacketReaderImplTest extends BriarTestCase {
 		try {
 			reader.readOffer();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -100,7 +100,7 @@ public class PacketReaderImplTest extends BriarTestCase {
 		try {
 			reader.readOffer();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -112,7 +112,7 @@ public class PacketReaderImplTest extends BriarTestCase {
 		try {
 			reader.readRequest();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	@Test
@@ -133,7 +133,7 @@ public class PacketReaderImplTest extends BriarTestCase {
 		try {
 			reader.readRequest();
 			fail();
-		} catch(FormatException expected) {}
+		} catch (FormatException expected) {}
 	}
 
 	private byte[] createAck(boolean tooBig) throws Exception {
@@ -142,11 +142,11 @@ public class PacketReaderImplTest extends BriarTestCase {
 		Writer w = writerFactory.createWriter(out);
 		w.writeListStart();
 		w.writeListStart();
-		while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
+		while (out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
 				< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
 			w.writeRaw(TestUtils.getRandomId());
 		}
-		if(tooBig) w.writeRaw(TestUtils.getRandomId());
+		if (tooBig) w.writeRaw(TestUtils.getRandomId());
 		w.writeListEnd();
 		w.writeListEnd();
 		assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
@@ -176,11 +176,11 @@ public class PacketReaderImplTest extends BriarTestCase {
 		Writer w = writerFactory.createWriter(out);
 		w.writeListStart();
 		w.writeListStart();
-		while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
+		while (out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
 				< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
 			w.writeRaw(TestUtils.getRandomId());
 		}
-		if(tooBig) w.writeRaw(TestUtils.getRandomId());
+		if (tooBig) w.writeRaw(TestUtils.getRandomId());
 		w.writeListEnd();
 		w.writeListEnd();
 		assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
@@ -210,11 +210,11 @@ public class PacketReaderImplTest extends BriarTestCase {
 		Writer w = writerFactory.createWriter(out);
 		w.writeListStart();
 		w.writeListStart();
-		while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
+		while (out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
 				< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
 			w.writeRaw(TestUtils.getRandomId());
 		}
-		if(tooBig) w.writeRaw(TestUtils.getRandomId());
+		if (tooBig) w.writeRaw(TestUtils.getRandomId());
 		w.writeListEnd();
 		w.writeListEnd();
 		assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
diff --git a/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java b/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java
index 38913a03c7..ea5701c992 100644
--- a/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java
+++ b/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java
@@ -240,7 +240,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
 		private volatile boolean messageAdded = false;
 
 		public void eventOccurred(Event e) {
-			if(e instanceof MessageAddedEvent) messageAdded = true;
+			if (e instanceof MessageAddedEvent) messageAdded = true;
 		}
 	}
 }
diff --git a/briar-tests/src/org/briarproject/plugins/ConnectionRegistryImplTest.java b/briar-tests/src/org/briarproject/plugins/ConnectionRegistryImplTest.java
index 045a774f1b..b2237b57f1 100644
--- a/briar-tests/src/org/briarproject/plugins/ConnectionRegistryImplTest.java
+++ b/briar-tests/src/org/briarproject/plugins/ConnectionRegistryImplTest.java
@@ -75,7 +75,7 @@ public class ConnectionRegistryImplTest extends BriarTestCase {
 		try {
 			c.unregisterConnection(contactId, transportId);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		// Register both contacts with one transport, one contact with both -
 		// this should broadcast two ContactConnectedEvents
 		c.registerConnection(contactId, transportId);
diff --git a/briar-tests/src/org/briarproject/plugins/DuplexClientTest.java b/briar-tests/src/org/briarproject/plugins/DuplexClientTest.java
index 7b47ecef74..2646dfec7e 100644
--- a/briar-tests/src/org/briarproject/plugins/DuplexClientTest.java
+++ b/briar-tests/src/org/briarproject/plugins/DuplexClientTest.java
@@ -20,7 +20,7 @@ public abstract class DuplexClientTest extends DuplexTest {
 		assert plugin != null;
 		// Start the plugin
 		System.out.println("Starting plugin");
-		if(!plugin.start()) {
+		if (!plugin.start()) {
 			System.out.println("Plugin failed to start");
 			return;
 		}
@@ -28,14 +28,14 @@ public abstract class DuplexClientTest extends DuplexTest {
 			// Try to connect to the server
 			System.out.println("Creating connection");
 			DuplexTransportConnection d = plugin.createConnection(contactId);
-			if(d == null) {
+			if (d == null) {
 				System.out.println("Connection failed");
 				return;
 			} else {
 				System.out.println("Connection created");
 				receiveChallengeSendResponse(d);
 			}
-			if(!plugin.supportsInvitations()) {
+			if (!plugin.supportsInvitations()) {
 				System.out.println("Skipping invitation test");
 				return;
 			}
@@ -43,7 +43,7 @@ public abstract class DuplexClientTest extends DuplexTest {
 			System.out.println("Creating invitation connection");
 			PseudoRandom r = getPseudoRandom(123);
 			d = plugin.createInvitationConnection(r, CONNECTION_TIMEOUT);
-			if(d == null) {
+			if (d == null) {
 				System.out.println("Connection failed");
 				return;
 			} else {
diff --git a/briar-tests/src/org/briarproject/plugins/DuplexServerTest.java b/briar-tests/src/org/briarproject/plugins/DuplexServerTest.java
index 49fdad0885..28bfadea20 100644
--- a/briar-tests/src/org/briarproject/plugins/DuplexServerTest.java
+++ b/briar-tests/src/org/briarproject/plugins/DuplexServerTest.java
@@ -21,18 +21,18 @@ public abstract class DuplexServerTest extends DuplexTest {
 		assert plugin != null;
 		// Start the plugin
 		System.out.println("Starting plugin");
-		if(!plugin.start()) {
+		if (!plugin.start()) {
 			System.out.println("Plugin failed to start");
 			return;
 		}
 		try {
 			// Wait for a connection
 			System.out.println("Waiting for connection");
-			if(!callback.latch.await(120, SECONDS)) {
+			if (!callback.latch.await(120, SECONDS)) {
 				System.out.println("No connection received");
 				return;
 			}
-			if(!plugin.supportsInvitations()) {
+			if (!plugin.supportsInvitations()) {
 				System.out.println("Skipping invitation test");
 				return;
 			}
@@ -40,7 +40,7 @@ public abstract class DuplexServerTest extends DuplexTest {
 			System.out.println("Creating invitation connection");
 			DuplexTransportConnection d = plugin.createInvitationConnection(
 					getPseudoRandom(123), CONNECTION_TIMEOUT);
-			if(d == null) {
+			if (d == null) {
 				System.out.println("Connection failed");
 				return;
 			} else {
diff --git a/briar-tests/src/org/briarproject/plugins/DuplexTest.java b/briar-tests/src/org/briarproject/plugins/DuplexTest.java
index e818e3bb25..ac5a45e5b0 100644
--- a/briar-tests/src/org/briarproject/plugins/DuplexTest.java
+++ b/briar-tests/src/org/briarproject/plugins/DuplexTest.java
@@ -31,10 +31,10 @@ abstract class DuplexTest {
 			out.flush();
 			System.out.println("Sent challenge: " + CHALLENGE);
 			Scanner in = new Scanner(r.getInputStream());
-			if(in.hasNextLine()) {
+			if (in.hasNextLine()) {
 				String response = in.nextLine();
 				System.out.println("Received response: " + response);
-				if(RESPONSE.equals(response)) {
+				if (RESPONSE.equals(response)) {
 					System.out.println("Correct response");
 				} else {
 					System.out.println("Incorrect response");
@@ -44,12 +44,12 @@ abstract class DuplexTest {
 			}
 			r.dispose(false, true);
 			w.dispose(false);
-		} catch(IOException e) {
+		} catch (IOException e) {
 			e.printStackTrace();
 			try {
 				r.dispose(true, true);
 				w.dispose(true);
-			} catch(IOException e1) {
+			} catch (IOException e1) {
 				e1.printStackTrace();
 			}
 		}
@@ -61,10 +61,10 @@ abstract class DuplexTest {
 		TransportConnectionWriter w = d.getWriter();
 		try {
 			Scanner in = new Scanner(r.getInputStream());
-			if(in.hasNextLine()) {
+			if (in.hasNextLine()) {
 				String challenge = in.nextLine();
 				System.out.println("Received challenge: " + challenge);
-				if(CHALLENGE.equals(challenge)) {
+				if (CHALLENGE.equals(challenge)) {
 
 					PrintStream out = new PrintStream(w.getOutputStream());
 					out.println(RESPONSE);
@@ -78,12 +78,12 @@ abstract class DuplexTest {
 			}
 			r.dispose(false, true);
 			w.dispose(false);
-		} catch(IOException e) {
+		} catch (IOException e) {
 			e.printStackTrace();
 			try {
 				r.dispose(true, true);
 				w.dispose(true);
-			} catch(IOException e1) {
+			} catch (IOException e1) {
 				e1.printStackTrace();
 			}
 		}
diff --git a/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java b/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java
index b046f3a6bc..d99ac2d56a 100644
--- a/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java
+++ b/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java
@@ -32,7 +32,7 @@ public class BluetoothClientTest extends DuplexClientTest {
 	}
 
 	public static void main(String[] args) throws Exception {
-		if(args.length != 1) {
+		if (args.length != 1) {
 			System.err.println("Please specify the server's Bluetooth address");
 			System.exit(1);
 		}
diff --git a/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java b/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java
index 061d6d007e..cfaf60c2c3 100644
--- a/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java
+++ b/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java
@@ -29,7 +29,7 @@ public class PollingRemovableDriveMonitorTest extends BriarTestCase {
 			private AtomicBoolean firstCall = new AtomicBoolean(true);
 
 			public Collection<File> findRemovableDrives() throws IOException {
-				if(firstCall.getAndSet(false)) return Collections.emptyList();
+				if (firstCall.getAndSet(false)) return Collections.emptyList();
 				else return Arrays.asList(file1, file2);
 			}
 		};
@@ -68,7 +68,7 @@ public class PollingRemovableDriveMonitorTest extends BriarTestCase {
 			private AtomicBoolean firstCall = new AtomicBoolean(true);
 
 			public Collection<File> findRemovableDrives() throws IOException {
-				if(firstCall.getAndSet(false)) return Collections.emptyList();
+				if (firstCall.getAndSet(false)) return Collections.emptyList();
 				else throw new IOException();
 			}
 		};
diff --git a/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java b/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java
index 6710db1d54..8d882679b8 100644
--- a/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java
+++ b/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java
@@ -27,7 +27,7 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
 
 	@Test
 	public void testNonexistentDir() throws Exception {
-		if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
+		if (!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
 			System.err.println("WARNING: Skipping test, can't run on this OS");
 			return;
 		}
@@ -48,7 +48,7 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
 
 	@Test
 	public void testOneCallbackPerFile() throws Exception {
-		if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
+		if (!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
 			System.err.println("WARNING: Skipping test, can't run on this OS");
 			return;
 		}
diff --git a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java
index 19168a5675..9f7a577402 100644
--- a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java
+++ b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java
@@ -35,7 +35,7 @@ public class LanTcpClientTest extends DuplexClientTest {
 	}
 
 	public static void main(String[] args) throws Exception {
-		if(args.length != 2) {
+		if (args.length != 2) {
 			System.err.println("Please specify the server's address and port");
 			System.exit(1);
 		}
diff --git a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java
index f3a321bbcc..fa609ecf8a 100644
--- a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java
+++ b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java
@@ -69,13 +69,13 @@ public class LanTcpPluginTest extends BriarTestCase {
 
 	private byte[] makeAddress(int... parts) {
 		byte[] b = new byte[parts.length];
-		for(int i = 0; i < parts.length; i++) b[i] = (byte) parts[i];
+		for (int i = 0; i < parts.length; i++) b[i] = (byte) parts[i];
 		return b;
 	}
 
 	@Test
 	public void testIncomingConnection() throws Exception {
-		if(!systemHasLocalIpv4Address()) {
+		if (!systemHasLocalIpv4Address()) {
 			System.err.println("WARNING: Skipping test, no local IPv4 address");
 			return;
 		}
@@ -107,7 +107,7 @@ public class LanTcpPluginTest extends BriarTestCase {
 
 	@Test
 	public void testOutgoingConnection() throws Exception {
-		if(!systemHasLocalIpv4Address()) {
+		if (!systemHasLocalIpv4Address()) {
 			System.err.println("WARNING: Skipping test, no local IPv4 address");
 			return;
 		}
@@ -131,7 +131,7 @@ public class LanTcpPluginTest extends BriarTestCase {
 				try {
 					ss.accept();
 					latch.countDown();
-				} catch(IOException e) {
+				} catch (IOException e) {
 					error.set(true);
 				}
 			}
@@ -155,10 +155,10 @@ public class LanTcpPluginTest extends BriarTestCase {
 	}
 
 	private boolean systemHasLocalIpv4Address() throws Exception {
-		for(NetworkInterface i : Collections.list(
+		for (NetworkInterface i : Collections.list(
 				NetworkInterface.getNetworkInterfaces())) {
-			for(InetAddress a : Collections.list(i.getInetAddresses())) {
-				if(a instanceof Inet4Address)
+			for (InetAddress a : Collections.list(i.getInetAddresses())) {
+				if (a instanceof Inet4Address)
 					return a.isLinkLocalAddress() || a.isSiteLocalAddress();
 			}
 		}
diff --git a/briar-tests/src/org/briarproject/system/LinuxSeedProviderTest.java b/briar-tests/src/org/briarproject/system/LinuxSeedProviderTest.java
index 6565c8b6e2..ff03eaccf3 100644
--- a/briar-tests/src/org/briarproject/system/LinuxSeedProviderTest.java
+++ b/briar-tests/src/org/briarproject/system/LinuxSeedProviderTest.java
@@ -29,13 +29,13 @@ public class LinuxSeedProviderTest extends BriarTestCase {
 
 	@Test
 	public void testSeedAppearsSane() {
-		if(!(OsUtils.isLinux())) {
+		if (!(OsUtils.isLinux())) {
 			System.err.println("WARNING: Skipping test, can't run on this OS");
 			return;
 		}
 		Set<Bytes> seeds = new HashSet<Bytes>();
 		LinuxSeedProvider p = new LinuxSeedProvider();
-		for(int i = 0; i < 1000; i++) {
+		for (int i = 0; i < 1000; i++) {
 			byte[] seed = p.getSeed();
 			assertEquals(SEED_BYTES, seed.length);
 			assertTrue(seeds.add(new Bytes(seed)));
@@ -44,7 +44,7 @@ public class LinuxSeedProviderTest extends BriarTestCase {
 
 	@Test
 	public void testEntropyIsWrittenToPool() throws Exception {
-		if(!(OsUtils.isLinux())) {
+		if (!(OsUtils.isLinux())) {
 			System.err.println("WARNING: Skipping test, can't run on this OS");
 			return;
 		}
@@ -62,7 +62,7 @@ public class LinuxSeedProviderTest extends BriarTestCase {
 
 	@Test
 	public void testSeedIsReadFromPool() throws Exception {
-		if(!(OsUtils.isLinux())) {
+		if (!(OsUtils.isLinux())) {
 			System.err.println("WARNING: Skipping test, can't run on this OS");
 			return;
 		}
diff --git a/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java b/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java
index 12880b1b8e..51493518c9 100644
--- a/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java
+++ b/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java
@@ -43,13 +43,13 @@ public class KeyManagerImplTest extends BriarTestCase {
 		secret2 = new byte[32];
 		secret3 = new byte[32];
 		secret4 = new byte[32];
-		for(int i = 0; i < secret0.length; i++) secret0[i] = 1;
-		for(int i = 0; i < secret1.length; i++) secret1[i] = 2;
-		for(int i = 0; i < secret2.length; i++) secret2[i] = 3;
-		for(int i = 0; i < secret3.length; i++) secret3[i] = 4;
-		for(int i = 0; i < secret4.length; i++) secret4[i] = 5;
+		for (int i = 0; i < secret0.length; i++) secret0[i] = 1;
+		for (int i = 0; i < secret1.length; i++) secret1[i] = 2;
+		for (int i = 0; i < secret2.length; i++) secret2[i] = 3;
+		for (int i = 0; i < secret3.length; i++) secret3[i] = 4;
+		for (int i = 0; i < secret4.length; i++) secret4[i] = 5;
 		initialSecret = new byte[32];
-		for(int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
+		for (int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
 	}
 
 	@Test
diff --git a/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java b/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java
index 84b6f89289..b5bcaa5b21 100644
--- a/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java
+++ b/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java
@@ -51,11 +51,11 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 		secret2 = new byte[32];
 		secret3 = new byte[32];
 		secret4 = new byte[32];
-		for(int i = 0; i < secret0.length; i++) secret0[i] = 1;
-		for(int i = 0; i < secret1.length; i++) secret1[i] = 2;
-		for(int i = 0; i < secret2.length; i++) secret2[i] = 3;
-		for(int i = 0; i < secret3.length; i++) secret3[i] = 4;
-		for(int i = 0; i < secret4.length; i++) secret4[i] = 5;
+		for (int i = 0; i < secret0.length; i++) secret0[i] = 1;
+		for (int i = 0; i < secret1.length; i++) secret1[i] = 2;
+		for (int i = 0; i < secret2.length; i++) secret2[i] = 3;
+		for (int i = 0; i < secret3.length; i++) secret3[i] = 4;
+		for (int i = 0; i < secret4.length; i++) secret4[i] = 5;
 		key0 = new byte[32];
 		key1 = new byte[32];
 		key2 = new byte[32];
@@ -66,13 +66,13 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 		k2 = new SecretKey(key2);
 		k3 = new SecretKey(key3);
 		k4 = new SecretKey(key4);
-		for(int i = 0; i < key0.length; i++) key0[i] = 1;
-		for(int i = 0; i < key1.length; i++) key1[i] = 2;
-		for(int i = 0; i < key2.length; i++) key2[i] = 3;
-		for(int i = 0; i < key3.length; i++) key3[i] = 4;
-		for(int i = 0; i < key4.length; i++) key4[i] = 5;
+		for (int i = 0; i < key0.length; i++) key0[i] = 1;
+		for (int i = 0; i < key1.length; i++) key1[i] = 2;
+		for (int i = 0; i < key2.length; i++) key2[i] = 3;
+		for (int i = 0; i < key3.length; i++) key3[i] = 4;
+		for (int i = 0; i < key4.length; i++) key4[i] = 5;
 		initialSecret = new byte[32];
-		for(int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
+		for (int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
 	}
 
 	@Test
@@ -154,7 +154,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -162,7 +162,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -170,7 +170,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -179,7 +179,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -187,7 +187,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -195,7 +195,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -256,7 +256,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -264,7 +264,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -272,7 +272,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -284,7 +284,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -292,7 +292,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -300,7 +300,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -369,7 +369,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -377,7 +377,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -385,7 +385,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -402,7 +402,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -410,7 +410,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -418,7 +418,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the updated tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 1; i < 17; i++) {
+			for (int i = 1; i < 17; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -478,7 +478,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -486,7 +486,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -494,7 +494,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -506,7 +506,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should remove the tags for period 0
 			oneOf(crypto).deriveTagKey(secret0, false);
 			will(returnValue(k0));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -514,7 +514,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -522,7 +522,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -581,7 +581,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -589,7 +589,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -597,7 +597,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 3
 			oneOf(crypto).deriveTagKey(secret3, false);
 			will(returnValue(k3));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -609,7 +609,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 1
 			oneOf(crypto).deriveTagKey(secret1, false);
 			will(returnValue(k1));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -617,7 +617,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -625,7 +625,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should remove the tags for period 3
 			oneOf(crypto).deriveTagKey(secret3, false);
 			will(returnValue(k3));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -686,7 +686,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -694,7 +694,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 3
 			oneOf(crypto).deriveTagKey(secret3, false);
 			will(returnValue(k3));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -702,7 +702,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 4
 			oneOf(crypto).deriveTagKey(secret4, false);
 			will(returnValue(k4));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k4),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -714,7 +714,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 2
 			oneOf(crypto).deriveTagKey(secret2, false);
 			will(returnValue(k2));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -722,7 +722,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should remove the tags for period 3
 			oneOf(crypto).deriveTagKey(secret3, false);
 			will(returnValue(k3));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -730,7 +730,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
 			// The recogniser should derive the tags for period 4
 			oneOf(crypto).deriveTagKey(secret4, false);
 			will(returnValue(k4));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(k4),
 						with((long) i));
 				will(new EncodeTagAction());
diff --git a/briar-tests/src/org/briarproject/transport/ReorderingWindowTest.java b/briar-tests/src/org/briarproject/transport/ReorderingWindowTest.java
index f2b9f5837b..db802cd1d8 100644
--- a/briar-tests/src/org/briarproject/transport/ReorderingWindowTest.java
+++ b/briar-tests/src/org/briarproject/transport/ReorderingWindowTest.java
@@ -14,7 +14,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 	@Test
 	public void testWindowSliding() {
 		ReorderingWindow w = new ReorderingWindow();
-		for(int i = 0; i < 100; i++) {
+		for (int i = 0; i < 100; i++) {
 			assertFalse(w.isSeen(i));
 			w.setSeen(i);
 			assertTrue(w.isSeen(i));
@@ -24,7 +24,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 	@Test
 	public void testWindowJumping() {
 		ReorderingWindow w = new ReorderingWindow();
-		for(int i = 0; i < 100; i += 13) {
+		for (int i = 0; i < 100; i += 13) {
 			assertFalse(w.isSeen(i));
 			w.setSeen(i);
 			assertTrue(w.isSeen(i));
@@ -42,7 +42,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 			// Centre is 32, highest value in window is 47
 			w.setSeen(48);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		// Centre is max - 1, highest value in window is max
 		byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
 		w = new ReorderingWindow(MAX_32_BIT_UNSIGNED - 1, bitmap);
@@ -52,7 +52,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 		try {
 			w.setSeen(MAX_32_BIT_UNSIGNED + 1);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		w.setSeen(MAX_32_BIT_UNSIGNED);
 		assertTrue(w.isSeen(MAX_32_BIT_UNSIGNED));
 		// Centre should have moved to max + 1
@@ -65,7 +65,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 		try {
 			w.setSeen(MAX_32_BIT_UNSIGNED + 1);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 	}
 
 	@Test
@@ -75,7 +75,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 		try {
 			w.setSeen(-1);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		// Slide the window
 		w.setSeen(15);
 		// Centre is 16, lowest value in window is 0
@@ -87,7 +87,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 		try {
 			w.setSeen(0);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		// Slide the window
 		w.setSeen(25);
 		// Centre is 26, lowest value in window is 10
@@ -95,7 +95,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 		try {
 			w.setSeen(9);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		// Centre should still be 26
 		assertEquals(26, w.getCentre());
 		// The bits corresponding to 10, 15, 16 and 25 should be set
@@ -112,7 +112,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 		try {
 			w.setSeen(15);
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 	}
 
 	@Test
@@ -121,7 +121,7 @@ public class ReorderingWindowTest extends BriarTestCase {
 		// Centre is 0; window should cover 0 to 15, inclusive, with none seen
 		Collection<Long> unseen = w.getUnseen();
 		assertEquals(16, unseen.size());
-		for(int i = 0; i < 16; i++) {
+		for (int i = 0; i < 16; i++) {
 			assertTrue(unseen.contains(Long.valueOf(i)));
 			assertFalse(w.isSeen(i));
 		}
@@ -130,8 +130,8 @@ public class ReorderingWindowTest extends BriarTestCase {
 		// Centre is 5; window should cover 0 to 20, inclusive, with two seen
 		unseen = w.getUnseen();
 		assertEquals(19, unseen.size());
-		for(int i = 0; i < 21; i++) {
-			if(i == 3 || i == 4) {
+		for (int i = 0; i < 21; i++) {
+			if (i == 3 || i == 4) {
 				assertFalse(unseen.contains(Long.valueOf(i)));
 				assertTrue(w.isSeen(i));
 			} else {
@@ -143,8 +143,8 @@ public class ReorderingWindowTest extends BriarTestCase {
 		// Centre is 20; window should cover 4 to 35, inclusive, with two seen
 		unseen = w.getUnseen();
 		assertEquals(30, unseen.size());
-		for(int i = 4; i < 36; i++) {
-			if(i == 4 || i == 19) {
+		for (int i = 4; i < 36; i++) {
+			if (i == 4 || i == 19) {
 				assertFalse(unseen.contains(Long.valueOf(i)));
 				assertTrue(w.isSeen(i));
 			} else {
diff --git a/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java b/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java
index 37c979f2d1..5512f7bd45 100644
--- a/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java
+++ b/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java
@@ -91,7 +91,7 @@ public class StreamWriterImplTest extends BriarTestCase {
 			oneOf(encrypter).writeFrame(with(any(byte[].class)),
 					with(MAX_PAYLOAD_LENGTH), with(0), with(false));
 		}});
-		for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
+		for (int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
 		context.assertIsSatisfied();
 
 		// Clean up
diff --git a/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java b/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java
index b901678a6b..a327bdaa9c 100644
--- a/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java
+++ b/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java
@@ -24,20 +24,20 @@ class TestStreamDecrypter implements StreamDecrypter {
 
 	public int readFrame(byte[] payload) throws IOException {
 		int offset = 0;
-		while(offset < HEADER_LENGTH) {
+		while (offset < HEADER_LENGTH) {
 			int read = in.read(frame, offset, HEADER_LENGTH - offset);
-			if(read == -1) throw new EOFException();
+			if (read == -1) throw new EOFException();
 			offset += read;
 		}
 		boolean finalFrame = (frame[0] & 0x80) == 0x80;
 		int payloadLength = ByteUtils.readUint16(frame, 0) & 0x7FFF;
-		while(offset < frame.length) {
+		while (offset < frame.length) {
 			int read = in.read(frame, offset, frame.length - offset);
-			if(read == -1) break;
+			if (read == -1) break;
 			offset += read;
 		}
-		if(!finalFrame && offset < frame.length) throw new EOFException();
-		if(offset < HEADER_LENGTH + payloadLength + MAC_LENGTH)
+		if (!finalFrame && offset < frame.length) throw new EOFException();
+		if (offset < HEADER_LENGTH + payloadLength + MAC_LENGTH)
 			throw new FormatException();
 		System.arraycopy(frame, HEADER_LENGTH, payload, 0, payloadLength);
 		return payloadLength;
diff --git a/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java b/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java
index d78b4aa3c7..9034810183 100644
--- a/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java
+++ b/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java
@@ -25,16 +25,16 @@ class TestStreamEncrypter implements StreamEncrypter {
 
 	public void writeFrame(byte[] payload, int payloadLength,
 			int paddingLength, boolean finalFrame) throws IOException {
-		if(writeTag) {
+		if (writeTag) {
 			out.write(tag);
 			writeTag = false;
 		}
 		ByteUtils.writeUint16(payloadLength, frame, 0);
-		if(finalFrame) frame[0] |= 0x80;
+		if (finalFrame) frame[0] |= 0x80;
 		System.arraycopy(payload, 0, frame, HEADER_LENGTH, payloadLength);
-		for(int i = HEADER_LENGTH + payloadLength; i < frame.length; i++)
+		for (int i = HEADER_LENGTH + payloadLength; i < frame.length; i++)
 			frame[i] = 0;
-		if(finalFrame)
+		if (finalFrame)
 			out.write(frame, 0, HEADER_LENGTH + payloadLength + MAC_LENGTH);
 		else out.write(frame, 0, frame.length);
 	}
diff --git a/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java b/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java
index af006350ae..b4922bdea6 100644
--- a/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java
+++ b/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java
@@ -73,9 +73,9 @@ public class TransportIntegrationTest extends BriarTestCase {
 
 	private void read(InputStream in, byte[] dest) throws IOException {
 		int offset = 0;
-		while(offset < dest.length) {
+		while (offset < dest.length) {
 			int read = in.read(dest, offset, dest.length - offset);
-			if(read == -1) break;
+			if (read == -1) break;
 			offset += read;
 		}
 	}
diff --git a/briar-tests/src/org/briarproject/transport/TransportTagRecogniserTest.java b/briar-tests/src/org/briarproject/transport/TransportTagRecogniserTest.java
index 340745489d..94bdd86365 100644
--- a/briar-tests/src/org/briarproject/transport/TransportTagRecogniserTest.java
+++ b/briar-tests/src/org/briarproject/transport/TransportTagRecogniserTest.java
@@ -39,7 +39,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
 			// Add secret
 			oneOf(crypto).deriveTagKey(secret, !alice);
 			will(returnValue(tagKey));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -47,7 +47,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
 			// Remove secret
 			oneOf(crypto).deriveTagKey(secret, !alice);
 			will(returnValue(tagKey));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
 						with((long) i));
 				will(new EncodeTagAction());
@@ -74,7 +74,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
 			// Add secret
 			oneOf(crypto).deriveTagKey(secret, !alice);
 			will(returnValue(tagKey));
-			for(int i = 0; i < 16; i++) {
+			for (int i = 0; i < 16; i++) {
 				oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
 						with((long) i));
 				will(new EncodeTagAction());
diff --git a/briar-tests/src/org/briarproject/util/ByteUtilsTest.java b/briar-tests/src/org/briarproject/util/ByteUtilsTest.java
index fee925e205..24e9610170 100644
--- a/briar-tests/src/org/briarproject/util/ByteUtilsTest.java
+++ b/briar-tests/src/org/briarproject/util/ByteUtilsTest.java
@@ -52,11 +52,11 @@ public class ByteUtilsTest extends BriarTestCase {
 	public void testReadUint() {
 		byte[] b = new byte[1];
 		b[0] = (byte) 128;
-		for(int i = 0; i < 8; i++) {
+		for (int i = 0; i < 8; i++) {
 			assertEquals(1 << i, ByteUtils.readUint(b, i + 1));
 		}
 		b = new byte[2];
-		for(int i = 0; i < 65535; i++) {
+		for (int i = 0; i < 65535; i++) {
 			ByteUtils.writeUint16(i, b, 0);
 			assertEquals(i, ByteUtils.readUint(b, 16));
 			assertEquals(i >> 1, ByteUtils.readUint(b, 15));
diff --git a/briar-tests/src/org/briarproject/util/StringUtilsTest.java b/briar-tests/src/org/briarproject/util/StringUtilsTest.java
index d23dd397f3..0d3b331ade 100644
--- a/briar-tests/src/org/briarproject/util/StringUtilsTest.java
+++ b/briar-tests/src/org/briarproject/util/StringUtilsTest.java
@@ -19,11 +19,11 @@ public class StringUtilsTest extends BriarTestCase {
 		try {
 			StringUtils.fromHexString("12345");
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		try {
 			StringUtils.fromHexString("ABCDEFGH");
 			fail();
-		} catch(IllegalArgumentException expected) {}
+		} catch (IllegalArgumentException expected) {}
 		byte[] b = StringUtils.fromHexString("0102037F80");
 		assertArrayEquals(new byte[] {1, 2, 3, 127, -128}, b);
 		b = StringUtils.fromHexString("0a0b0c0d0e0f");
-- 
GitLab