move nsurl out of while