Refactoring and implementation of Foreach task. Ran into problems
with the Automata module.