Move check if ad has nextWrapperUrl at the beginning of the loop, not inside the closure