Compute offset as MAX(num) instead of COUNT(num).

This is needed as an history stack may not have continuous num values. This
can happen after applying a style or a partial copy/paste.
Remove dead code, can always be resurected from Git.