fixes the infinite loop to loop consistently between images