refactored algorithm exercises