bug fix in for statement