Improved code according to sonar warnings