refactoring for generality