Adding some comments to this logic would be helpful for those not yet initiated :)