added weighted average function