remove duplication
generalise dict creation
generalise dimension generators
break out main worker function