Some code cleanup and more unit tests, making Sonar happy