some final refactoring