Updated script and added a check if statement