Refactoring - add function _weighted_sum