include an optimization for output writing, should be a big speed up