Better variable names.
Added more tests.
Remember that test forms ka as an input parameter!
Codes that handle medium index of refraction multiply this parameter by Nmedium.
Maybe that's all you have to do!