refine ex2.57 with accumulate