fix variable naming/scope issues