Improve unit tests and sonar fixes