algo refactoring