Fixed last critical and some major issues reported by Sonar.