diff --git a/src/common/connection.py b/src/common/connection.py
index 4be317fd3b0a68314f81a8218fae81f56365def5..50d3c39f45a73d23f21e524f6887fb3499a04694 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -1062,6 +1062,9 @@ class Connection(ConnectionHandlers):
 		msgtxt = msg
 		msgenc = ''
 
+		if session:
+			fjid = str(session.jid)
+
 		if keyID and self.USE_GPG:
 			if keyID ==  'UNKNOWN':
 				error = _('Neither the remote presence is signed, nor a key was assigned.')
diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index d78c84f652f8ccc04daa37658e668f14bd9d8e1e..faf21d6b18290979eaeeea15eaa09b53cbfcd325 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -1226,23 +1226,37 @@ class ConnectionHandlersBase:
 		# keep track of sessions this connection has with other JIDs
 		self.sessions = {}
 
-	def get_or_create_session(self, jid, thread_id):
-		'''returns an existing session between this connection and 'jid', returns a new one if none exist.'''
+	def get_sessions(self, jid):
+		'''get all sessions for the given full jid'''
 
-		pm = True
 		if not gajim.interface.is_pm_contact(jid, self.name):
-			pm = False
 			jid = gajim.get_jid_without_resource(jid)
 
+		try:
+			return self.sessions[jid].values()
+		except KeyError:
+			return []
+
+	def get_or_create_session(self, fjid, thread_id):
+		'''returns an existing session between this connection and 'jid', returns a
+		new one if none exist.'''
+
+		pm = True
+		jid = fjid
+
+		if not gajim.interface.is_pm_contact(fjid, self.name):
+			pm = False
+			jid = gajim.get_jid_without_resource(fjid)
+
 		session = self.find_session(jid, thread_id)
 
 		if session:
 			return session
 
 		if pm:
-			return self.make_new_session(jid, thread_id, type = 'pm')
+			return self.make_new_session(fjid, thread_id, type='pm')
 		else:
-			return self.make_new_session(jid, thread_id)
+			return self.make_new_session(fjid, thread_id)
 
 	def find_session(self, jid, thread_id):
 		try:
@@ -1311,13 +1325,13 @@ sent a message to.'''
 		if not cls:
 			cls = gajim.default_session_type
 
+		sess = cls(self, common.xmpp.JID(jid), thread_id, type)
+
 		# determine if this session is a pm session
-		# if not, discard the resource
+		# if not, discard the resource so that all sessions are stored bare
 		if not type == 'pm':
 			jid = gajim.get_jid_without_resource(jid)
 
-		sess = cls(self, common.xmpp.JID(jid), thread_id, type)
-
 		if not jid in self.sessions:
 			self.sessions[jid] = {}
 
diff --git a/src/gajim.py b/src/gajim.py
index ec5354d3eceff2b27cded76d6193fc734d1cc6f1..24885944981842edbe3bfb0b8bdfce62c739af7e 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -769,10 +769,12 @@ class Interface:
 			if array[1] in ('offline', 'error'):
 				contact1.our_chatstate = contact1.chatstate = \
 					contact1.composing_xep = None
+
+				conn = gajim.connections[account]
+
 				# TODO: This causes problems when another
 				#	resource signs off!
-				gajim.connections[account]. \
-					remove_transfers_for_contact(contact1)
+				conn.remove_transfers_for_contact(contact1)
 
 				# disable encryption, since if any messages are
 				# lost they'll be not decryptable (note that
@@ -782,20 +784,16 @@ class Interface:
 				# FIXME: This *REALLY* are TOO many leves of
 				#	 indentation! We even need to introduce
 				#	 a temp var here to make it somehow fit!
-				if gajim.connections[account].sessions. \
-				has_key(ji):
-					for sess in gajim.connections \
-					[account]. sessions[ji].values():
-						ctrl = sess.control
-						if ctrl:
-							ctrl.no_autonegotiation\
-								= False
-						if sess.enable_encryption:
-							sess.terminate_e2e()
-							gajim.connections \
-							[account]. \
-							delete_session(jid,
-							sess.thread_id)
+				for sess in  conn.get_sessions(ji):
+					if (ji+'/'+resource) != str(sess.jid):
+						continue
+					ctrl = sess.control
+					if ctrl:
+						ctrl.no_autonegotiation = False
+					if sess.enable_encryption:
+						sess.terminate_e2e()
+						conn.delete_session(jid,
+						sess.thread_id)
 
 			self.roster.chg_contact_status(contact1, array[1],
 				status_message, account)
diff --git a/src/message_control.py b/src/message_control.py
index 89ae0f4a2511e14da67b7be9126e8998e1790ff0..b324d89d1c92dd79a9dfd86fdc39ed7df83185ca 100644
--- a/src/message_control.py
+++ b/src/message_control.py
@@ -160,6 +160,9 @@ class MessageControl:
 		if not self.session:
 			sess = conn.find_controlless_session(jid)
 
+			if self.resource:
+				jid += '/' + self.resource
+
 			if not sess:
 				sess = conn.make_new_session(jid)
 
diff --git a/src/session.py b/src/session.py
index 1de42bd975ba2aa590a73178800f9287b3306e74..97b04ac2bc160ab434bc2829453b0abae1f70717 100644
--- a/src/session.py
+++ b/src/session.py
@@ -440,7 +440,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
 		form.getField('terminate').getValue() in ('1', 'true'):
 			self.acknowledge_termination()
 
-			self.conn.delete_session(self.jid, self.thread_id)
+			self.conn.delete_session(str(self.jid), self.thread_id)
 
 			return