split save_output into two seperate functions