It was the script tag that was interfeering with the loop