Moved http authentication out of loop