Refactoring: adjust scope of variable