Some refactoring (phase 1)