variable scope bug and condition on new file