Fix a regression and many Sonar warnings