Redid the calculation algorithm

I redid the algorithm, although there are some bugs that i need to
squish. I will do that later today.