constness, unsigned chars, rationalise use of tempbuf