More variable scope fixes