Applying my updated version of Craig Barratt's buffered I/O patch.