The above code is duplicated below. Perhaps move it to a function called "adjust_scratchpad_margin", and call it from both places.