Refactor "path sum".