several bug fixes with I/O