build up proper output file