rearranged the parts of the script a bit