Rework to use IO.

- faster
- cleaner (it keeps track of our offset).