Roth IRA: Calculate earning on excess contribution

If anyone could help me with my questions it is really appreciated!

 

I have contributed too much to my Roth IRA account 2019 and am going to fix it. I run into some problems with calculating the earnings.
I contributed $5500 for 2018 and $6000 for 2019 in Jan 2019. In the year 2018 I still had a job and $5500 contribution is within the limit. I quit my job in 2019 and have to remove the excess contribution of $6000 and also its earnings.

 

The formula I am using:
Net Income=Contribution×(Adjusted Closing Balance−Adjusted Opening Balance)/Adjusted Opening Balance.

 

x = amount in my Roth IRA account 1.1.2019

 

For the AOB, is it x+5500 or x+5500+6000?

 

In Dec 2019 I moved money from my Tradition IRA to Roth IRA. Could you confirm this is NOT an excess contribution? There is no excess contribution in Trad IRA.

 

How do I calculate ACB in this case with the additional non-excess contribution in Roth IRA?