Refactor uses of scroll_margin to a function