Solved by vdw in post #2 
              
              
                If it works and it’s in line with the formulas given, it should be alright. 
I would recommend putting the calculations into their own methods, though. There’s a lot of copy&paste going one which makes to annoying to make changes, e.g., adding more layers. 
Maybe you can have a look at some older co…