Early Withdrawal from Roth IRA Older than 5 Years Including First-Time Home Exemption

I took an early withdrawal from my Roth IRA (which I have owned for more than 5 years) for a first time home purchase. I took 40K out and am aware that the exclusion to not pay a penalty and taxes is only on my contributions and the10K first time home buyer exemption. My contributions into the Roth were about 17K. For some reason form 1040 line 4b "taxable amount" is on $23k ($40k distribution minus the $17k in contributions). It doesn't take into account the $10k first time home buyer exemption. It is my understanding that in an early distribution from a Roth IRA which is over 5 years old, no penalty or taxes apply to the contributions and no penalty or taxes apply to the $10K home exemption. This leaves me to be taxed and penalized only on the $13k remainder in earnings. Form 5329 does have the $13k amount listed for the 10% penalty, but why am I being taxed on the $23k amount instead of the 13k amount? I indicated that I have owned the IRA for more than 5 years when prompted.