Handling edge cases

Covers only edge cases related to tracking, not yet
handling linking or updating. Getting a bit hairy,
must be refactored.
refactor, cleanup and tweak