Adding changes to script to more carefully process links