Add safety check.
Avoid running scrollbar offset changing code when selection has not changed.
Refactor.