Refactor3

Some more refactoring (still on dev branch).