massive refactoring and cleanup - step 3
massive refactoring and cleanup step 4