Poor variable scoping