More algorithms refactored