Massive refactoring. step 1