refactoring more or less finished