fix cumulative math functions and add some comments