first working version of TableDictionary (the logic is kind of ass-backwards, though)