Some refactoring. Not done yet.