improved I/O handling