edits to for loop for ids
fixed for loop to use sub() function