A bit more refactoring (still not finished)