I don't quite understand how this logic works, but it seems to work correctly and doesn't cause a huge performance hit.  Lets just keep this in the back of our heads if any performance issues start to arise.