Refactoring to reuse variables