Oops - thanks for pointing those out.
I had already corrected those mistakes but the code was very messy because I was trying different things so I pasted an earlier 'clean' version.
My main concern is with the functions that add & read to/from the queue -- those currently don't work I don't think. Has anybody spotted the mistake in those?