Refactoring the IO layer.

EVERYTHING should be broken right now.