Fixed errors causes by running the script multiple times.