Fixing some bugs in 'for'