Various fixes and refactoring
Various changes and fixes
Some changes and new weighting strategy