Properly scope local variables