Refactoring the io