     threadLock.wait()
 
     // got awoken
-    let state = threadLock.state
-    let match = threadLock.pointer == &newElement
-    threadLock.setState(.Done)
-    threadLock.pointer = nil
-    SemaphorePool.Return(threadLock)
-
-    switch state
+    defer {
+      threadLock.setState(.Done)
+      threadLock.pointer = nil
+      SemaphorePool.Return(threadLock)
+    }
+
+    switch threadLock.state
     {
     case .Done:
       // thread was awoken by close() and put() has failed
       return false
 
-    case .Pointer where match:
+    case .Pointer:
+      assert(threadLock.pointer == &newElement)
       // the message was succesfully passed.
-      return match
-
-    default:
+      return threadLock.pointer == &newElement
+
+    case let state: // default
       preconditionFailure("Unexpected Semaphore state \(state) after wait in \(__FUNCTION__)")
     }
   }

          // got awoken by insert()
          assert(threadLock.state == .Pointer && threadLock.pointer == buffer,
                 "Unexpected Semaphore state \(threadLock.state) in \(__FUNCTION__)")
          threadLock.setState(.Done)
          threadLock.pointer = nil
          SemaphorePool.Return(threadLock)

          let element = buffer.move()
          buffer.dealloc(1)
          return element
        }

      case .Select, .DoubleSelect, .Invalidated, .Done:

          OSSpinLockUnlock(&lock)
          let threadLock = SemaphorePool.Obtain()
          let buffer = UnsafeMutablePointer<T>.alloc(1)
          defer { buffer.dealloc(1) }
          threadLock.setState(.Pointer)
          threadLock.pointer = UnsafeMutablePointer(buffer)
          writer.sem.selection = writer.sel.withSemaphore(threadLock)
