added save output function