factored out construction of optimized dictionary structure