bug fix at foreach