some refactoring (not finished)