Modify script to solve a bug