Why A2 and not A1
The range string 'A2:D' is the most load-bearing part of this script. If you pass 'A1:D', the sort treats row 1 as a data row, not a header, and on the first matching edit your column labels get shuffled into the middle of the data. Starting at row 2 keeps the header anchored outside the range the sort can touch.
The first time I hit this it was subtle: the sort ran cleanly for two edits, then on the third a new row happened to sort above row 1 and the header disappeared. Setting DATA_RANGE to start at row 2 is the fix, not a defensive check inside the function.