Fix issues with variable scoping in server file