Change loop range to eliminate script out of bounds errors