Refactored code for focus