Fixed premature exit of for loop for picture ids
Refactored picture Id replacement logic