Not clear looking at this that the input is always sorted with newest first. Add comment.