refactored code for sonar