The problem seems to be two-fold - the wrong detflag is arguably being tested, and the ToolHandles are retrieved unless the key is set to null.