added test for forLoop and fixed uncovered bugs