Separate io

Made some progress in pull out IO code from repex.