Fixed nasty bug in stream copying