Some adjustments, some refactoring. Not finished.