Added unit tests and further Sonar fixes.