Added option to set output type

Also improved output data accumulation.