Added waitUntillClosed and a better forkIO