Refactor 'minimum path sum'.