Need help understanding a pyteal example

Hi everyone, I recently started learning pyteal and the official examples have helped a lot. But I had a few problems going through the periodic payment example.

The questions are very basic and may seem stupid, so thanks in advance for any help!

  1. I don’t understand the purpose of line 29, where it checks that Txn.first_valid() % tmpl_period == Int(0) and tmpl_period = Int(50). Is this necessary?

  2. In the following line, the code ensures that Txn.last_valid() == tmpl_dur + Txn.first_valid(), where tmpl_dur = Int(5000). But in line 49 of the the deployment script, the gap between endRound and startRound seems to be 1000. How could this transaction get approved?

  3. In the deployment script, the fv was defined as: startRound = params[“lastRound”] - (params[“lastRound”] % 1000). What’s the benefit of doing this subtraction? Because I think the default fv in algod_client.suggested_params is just params[“lastRound”].