Refactoring sonar

Reduced violations that Sonar flagged.