Second part of migration and refactoring