Thanks for the prompt reply and pointing that out, Simon. train_var is pre_R and I edited it in the code snippet. It was a small editing mistake in the question posted here as I was ttrying to simplify it for anyone to understand.
Please note that the behavior of the loss is still the same.