Main code reorganize