refactored to set output filename at single point