Very big refactoring.