Fixed a few bugs reported by Sonar.
Fixed a few errors as per Sonar