calcHistogram and saveOutput as separate functions when calculating statistics