adjusted code for multiple images. Tested working.