Performance fixes

As suggested by Sonar.
Extracted an inner function that used no state to a static function