Shadow code fixes

Rewrote shadow code from scratch to fix variable distance problems