Moved stuff outside loop