XD-911 Reduce the number of critical errors

* Clear up some of the critical errors reported by Sonar.
* Remove Package Tangles reported by Sonar
* Remove some of the major errors reported by Sonar