tweaked I/O logic for simplicity