More for Sonar.  Replaced "magic numbers" with constants and removed
more duplicate code.