add a weighted average function