refactoring algorithms