Correct use of weights variable.
Remove unnecessary code.