Refactoring to improve code clarity