Complete (untested) implementation of weights.v