Loop downloads pages 7,1,9 instead of 7,8,9

The script below is meant to download some pages from a website.
My repeat loop tells it to do pages 7 to 9, yet it downloads pages 7, 1, 9(in that order). What is going on here ?

  
to goToWebPage(theWebPage)
	tell application "Safari"
		activate
		set URL of document 1 to theWebPage
	end tell
end goToWebPage

on waitSafariWebPageLoading()
	tell application "System Events" to tell application process "Safari"
		repeat until ((UI element "Reload this page" of group 3 of toolbar 1 of window 1 exists) or (UI element "Reload this page" of group 2 of toolbar 1 of window 1 exists))
			delay 0.1
		end repeat
	end tell
end waitSafariWebPageLoading

to downloadPage(pageNumber)
	goToWebPage("https://babel.hathitrust.org/cgi/pt?id=iau.31858047945971&view=1up&seq=" & pageNumber)
	waitSafariWebPageLoading()
	delay 2
	tell application "Safari"
		
		do JavaScript "document.getElementsByClassName('btn')[24].click();" in document 1
		delay 7
	end tell
	
end downloadPage

repeat with pageNum from 7 to 9
	downloadPage(pageNum)
end repeat