account was established. (4) Certain rules to Apply Rules similar to the following rules shall apply for purposes of this section: (A) Section 219(d)(2) (relating to no deduction for rollovers). (B) Section 219(f)(3) (relating to time when contributions deemed made). (C) Except as provided in section 106(d), section 219(f)(5) (relating to employer payments). (D) Section 408(g) (relating to community property laws). (E) Section 408(h) (relating to custodial accounts). (e) Tax treatment of accounts (1) In general A health savings account is exempt from taxation under this subtitle unless such account has ceased to be a health savings account. Notwithstanding the preceding sentence, any such account is subject to the taxes imposed by section 511 (relating to imposition of tax on unrelated business income of charitable, etc. organizations). (2) Account terminations Rules similar to the rules of paragraphs (2) and (4) of section 408(e) shall apply to health savings accounts, and any amount treated as distributed under such rules shall be treated as not used to pay qualified medical expenses. (f) Tax treatment of distributions (1) Amounts used for qualified medical expenses Any amount paid or distributed out of a health savings account which is used exclusively to pay qualified medical expenses of any account beneficiary shall not be includible in gross income. (2) Inclusion of amounts not used for qualified medical expenses Any amount paid or distributed out of a health savings account which is not used exclusively to pay the qualified medical expenses of the account beneficiary shall be included in the gross income of such beneficiary. (3) Excess contributions returned before due date of return (A) In general If any excess contribution is contributed for a taxable year to any health savings account of an individual, paragraph (2) shall not apply to distributions from the health savings accounts of such individual (to the extent such distributions do not exceed the aggregate excess contributions to all such accounts