added scoping to functions