Some refactoring.
Implements first step of RM2