refactored io stuff