[core] Main partly refactored.