refactoring io code.