SDM: Code cleanup part 3: random shape-perturbations & moved all functions to the cpp file