Fix definite integration and make sum