revisions to script if then loops