Some final refactoring