refactoring i/o, events, trace (in progress)