Refactor to allow recalculating indexes when  weights are changed.