Some work on #17. Rework io a little for js.