                 for ev in events {
                     if ev.selectable is Socket {
                         let channel = ev.attachment as! Channel
-                        guard channel.open else {
-                            safeDeregister(channel: channel)
+
+                        guard handleEvents(channel) else {
                             continue
                         }
-                        
+
                         if ev.isWritable {
                             channel.flushFromEventLoop()
                             
-                            guard channel.open else {
-                                safeDeregister(channel: channel)
+                            guard handleEvents(channel) else {
                                 continue
                             }
                         }

                        if ev.isReadable {
                            channel.readFromEventLoop()
                            
                            guard channel.open else {
                                safeDeregister(channel: channel)
                                continue
                            }
                        }
                        
                        assert(channel.open)
                        assert(ev.isReadable || ev.isWritable)
                    
                    } else if ev.selectable is ServerSocket {
                        let socket = ev.selectable as! ServerSocket
                        

                }
            }
        }
    }

    private func handleEvents(_ channel: Channel) -> Bool {
        if channel.open {
            return true
        }
        do {
            try deregister(channel: channel)
        } catch {
            // ignore for now... We should most likely at least log this.
        }

        return false
    }
    
    public func close() throws {
