Fixed critical issues reported by sonar