some work on how to handle loop detection of links

WARNING: code is in an unconsistent state, it wont compile