few corrections to get it running ok and outputting the stream