refactoring (not finished!)