bug fix

make func out of loop