Refactored scroll spy handling.