Eliminate deadlocks on I/O

Fixes #2