fix bug with outputdir variable when in a loop