Small refactoring of code in softConstraints function