Added Keith Rose's code.
Got weight working.
Merge branch 'weighted'