REG-anyone can explain this corporation distribution question to me?

So the background of this question involves shareholder treatment of distribution from corporation. Corporation distributed $90,000 when E&P are $60,000. Shareholder N receives $30,000 of the distribution, of which $20,000 is a dividend (2/3). Block 1 Number of shares #1000 Basis $3,000 Dividend $10,000 Capital Recovery $3,000 Gain $2,000 Block 2 #of shares: #1,000 Basis $15,000 Dividend $10,000 Capital recovery: $5,000 Gain: 0 Why on the second block, the capital recovery amount does not equal the basis? The gain seems to be calculated by using the total dividend to subtract the total basis, then why the gain is allocated to block 1 entirely? Overall this example further confuses me with how excess dividend is divided amount capital recovery and gain on sale.