In addition, this code rewrites encode to just defer to encode_io. This is an attempt to fix #2, though I believe the lookahead code can and should be refined.