Rework some sonar critical and major bugs