Bunch of fixes for IO.copy_stream