I feel like the logic here could stand to be written out longhand, since this is honestly kind of obscure, and the multiple brackets really highlight that.