Bug fixes to work on Windows
Major fiddling to stop time out errors on Windows when trying to read
back the buffer