Minor code clean OrderedDict

reduce code duplication

also clean up the imports in these files