partial refactoring
finished refactoring