Fixed bugs: loop, initialization