small fix: moving the url length check in the inner loop