Refactored descent function.