Fix problems reported by Sonar.