Fixed various issues reported by sonar