Fixed variable names and scoping