code refactoring and reorganization