WIP Fixing ref counting of keydirs and itrs
Reworked global keydirs and refcounting