added variable scoping and