Determining taxable portion of 529

My child is a first year college student.  We were not knowledgeable about the AOTC so we withdrew funds from an 529 plan to cover tuition (amount remaining after scholarship was applied...$6527) and room and board ($11285).  We also paid $700 out of pocket for books and an enrollment deposit totaling. In maximizing our refund TT adjusted our 529 distribution to non-taxable and taxable amounts so that we can qualify for the $2500 AOTC. Great! However the taxable amount of the 529 that is now appearing on line 8 is $3970 and there is no link to the formula, amounts, and calculations used to determine this amount.  Using the formula of qualified expenses / total distribution X earnings  I can back into the numbers and see that it is only applying the $11,285 of room and board as qualified expenses.  The $6527 remaining tuition cost and $700 out of pocket costs were not included in the calculation.  Why is turbo tax not applying these amounts to qualified expenses and then removing the $4000 from that amount that would allow for the AOTC? 

Currently the calculation is:

$11,285/$17,812 X $10,835 (earnings) =$6,864.   $10,835-$6864=$3,970

I believe it should be this: $11,285 (room and board) +$6,527 (remaining tuition after scholarship) +$700 (out of pocket qualified cost) - $4000 ( amount that needs to be removed from qualified expenses to qualify for AOTC) so the calculation would be:

$14,512/$17,812 X $10,835 = $8,828 (non-taxable)  $10,835-$8,828= $2,007

This means that line 8 on the 1040 should be $2,007 not what TT calculated as $3,970.  What am I  missing? Why did TT not included these other amounts as qualified expenses? Thanks in advance!!