This program could lose steps with hard stops that occur when it activates a limit switch.
If it is a concern, I'd set the limit/homing/reference switches such that you could go past them a little bit, and make the return target at -5 or -10 or so, so you could decelerate smoothly to a stop at a place that engagnes the limit switch, and also get a measure of system health & reliability each cycle.
The AccelStepper examples cover a few quick stops that have controlled deceleration: