Some code refactoring
Merge with agrandi