Added loops, variable scoping