algorithm refactored