move variable init outside loop