diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+0.5.1
+* Fixed bug in cleanup procedure.
 0.5 
 * Complete reimplementation based on STM primitives.
 * Rename Network.Transport.Chan to Network.Transport.InMemory.
diff --git a/network-transport-inmemory.cabal b/network-transport-inmemory.cabal
--- a/network-transport-inmemory.cabal
+++ b/network-transport-inmemory.cabal
@@ -1,11 +1,11 @@
 Name:          network-transport-inmemory
-Version:       0.5.0
+Version:       0.5.1
 Cabal-Version: >=1.8
 Build-Type:    Simple
 License:       BSD3
 License-file:  LICENSE
 Copyright:     Well-Typed LLP, Tweag I/O Limited
-Author:        Duncan Coutts, Nicolas Wu, Edsko de Vries
+Author:        Duncan Coutts, Nicolas Wu, Edsko de Vries, Alexander Vershilov
 Maintainer:    Facundo Domínguez <facundo.dominguez@tweag.io>
 Stability:     experimental
 Homepage:      http://haskell-distributed.github.com
@@ -15,7 +15,7 @@
                communication in the same address space (i.e. one process).
                .
                It could be used either for testing purposes or for local
-			   communication that require the network-transport semantics.
+               communication that require the network-transport semantics.
                .
                NB: network-tranpsport-inmemory does not support cross-transport
                communication. All endpoints that want to comminicate should be
diff --git a/src/Network/Transport/InMemory.hs b/src/Network/Transport/InMemory.hs
--- a/src/Network/Transport/InMemory.hs
+++ b/src/Network/Transport/InMemory.hs
@@ -17,10 +17,9 @@
 import Control.Concurrent.STM
 import Control.Exception (handle, throw)
 import Data.Map (Map)
-import Data.Maybe (fromMaybe, fromJust)
+import Data.Maybe (fromJust)
 import Data.Monoid
 import Data.Foldable
-import Data.Traversable
 import qualified Data.Map as Map
 import Data.Set (Set)
 import qualified Data.Set as Set
@@ -196,8 +195,10 @@
         whenValidLocalEndPointState lep $ \lepvst -> do
           let (cl, other) = Map.partitionWithKey (\(addr,_) _ -> addr == b)
                                                  (lepvst ^.connections)
-          forM_ cl $ \c -> writeTVar (localConnectionState c)
-                                     LocalConnectionFailed
+          forM_ cl $ \c -> modifyTVar (localConnectionState c)
+                                      (\x -> case x of
+                                               LocalConnectionValid -> LocalConnectionFailed
+                                               _ -> x)
           writeTChan (localEndPointChannel lep)
                      (ErrorEvent (TransportError (EventConnectionLost b) msg))
           writeTVar (localEndPointState lep)
