refactoring (not yet finished)