Some refactorations (not finished yet)