Fixed some sonar warnings and added some unit tests