change the randfold command and optimize the code