Implemented dimension weighting; fixed some bugs.
Fixes #2
Fixes #3