Added Rmath and modified sample generation