Refactoring, still having IO issues