Some general refactoring