Refactoring based on input from Fabien4.