Added comments to help understand and track logic flow