Fixed link path script with better logic.