refactoring (not well done)