fix unit tests and a bunch of Sonar "Critical" issues