Fixed Picture id processing

Fixed Issue with premature exit of for loop
Refactored logic checking if picture id requires replacement