Some refactoring (supposed to be squashed with previous previous commit).