Factoring out some useful stuff from hash map and templatize.