added fold_and_print to reduce dublicated code