Added weight and class parameter sampling to algorithm 2