Outline shader inside/outside edge bug?

I followed this tutorial Here which shows how to draw an outline on the edge of an object based on scene depth, which many other tutorials have also done. This tutorial also shows how to draw the outline on just the inside of an object or just on the outside of an object.


For my project i would like to only show an outline along the inside edge of an object which the tutorial allows me to do but i ran into a bug where the outline along the outside of an object is still there just not being colored like the outline but it covers the inside outline of other objects at certain angles.
Show inside edges only

The same thing happens but the opposite with just drawing the outside outlines. The inside edges arent being colored like the outline but still show and cover the outside edge being drawn.

If theres a better method to detect inside edges only or changes that need to be done to the material math i would greatly appreciate any help or tips. thx