Rewrote the directory tracking alg.