Move domain() and getUri() out of foreach loop