prevent the same pic from loading

I tried to do it the same as the while loop in the current version but I
couldn't get it to work. The code is in comments.