Fixed some critical issues reported by sonar