Entire block within the `for` loop is copied from the `if (url != null)` above. Worth making a function?