variable scope fixes