fixed a bug in the perturbate function