Major rewrite to pass file descriptors