partial refactoring finished