Lots of changes. Added purity and RSS calculations.