improved integral calculation. fixed add.