Refactor to use dispatch_io for tasks, and wait for EOF

Hopefully resolves #151, #139, and #135.

/cc @joshaber @keithduncan