adding weightedmidpoint function